Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
从键盘输入一行字符(长度小于100),统计其中单词的个数,各单词以空格分隔,且空格数可以是多个。
Input
输入只有一行句子。仅有空格和英文字母构成。
Output
单词的个数。
Sample Input
stable marriage problem Consists of Matching members
Sample Output
7
Hint
Source
本题 思路 :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char a[101];
int worde=0,count=0,i;
gets(a);
for(i=0;a[i]!='\0';i++)
{
if(a[i]==' ') worde = 0;
else if(worde==0)
{
count++;
worde=1;
}
}
printf("%d\n",count);
return 0;
}
运行结果:
stable marriage problem Consists of Matching members
7
Process returned 0 (0x0) execution time : 3.746 s
Press any key to continue.