题目描述
从键盘输入一行字符(长度小于100),统计其中单词的个数,各单词以空格分隔,且空格数可以是多个。
输入
输入只有一行句子。仅有空格和英文字母构成。
输出
单词的个数。
示例输入
stable marriage problem Consists of Matching members
示例输出
7
#include <stdio.h>
#include <string.h>int main()
{
char a[80];
int i=0,n,count=0;
gets(a);
n=strlen(a);
while(i<n)
{
if(a[i]!=' ')
count++;
while(a[i]!=' '&&i<n)
i++;
i++;
}
printf("%d\n",count);
return 0;
}