View Code of Problem 58

#include <stdio.h>
//从键盘输入一行字符,统计其中单词的个数,各单词以空格分隔,且空格数可以是多个。输入只有一行句子。仅有空格和英文字母构成。单词的个数。
int main()
{
  int i;
  int p=0,q=0; 
  char str[100];
  gets(str);
  for(i=0;str[i]!='\0';i++)
  {
    if(str[i] >='A' && str[i]<='z')
    {  
      if(q==0)
        p++;   
	  q = 1;
	}
	else 
	{
	   if(str[i]=' ')
	     q = 0;	
    }
  }
  printf("%d",p);
  return 0;
}

Double click to view unformatted code.


Back to problem 58