Description
从键盘输入一行字符(长度小于100),统计其中单词的个数,各单词以空格分隔,且空格数可以是多个。
Input
输入只有一行句子。仅有空格和英文字母构成。
Output
单词的个数。
Sample
Input
stable marriage problem Consists of Matching members
Output
7
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main(){
char s[101];
int i, l, countword = 0, isword = 0;
gets(s);
l = strlen(s);
for(i = 0; i < l; i++){
if(s[i] == ' '){
isword = 0;
}
else if(isword == 0){
isword = 1;
countword++;
}
}
printf("%d\n", countword);
return 0;
}