1178
描述
从键盘输入一行字符,统计其中单词的个数,各单词以空格分隔,且空格数可以是多个。
输入
输入只有一行句子。仅有空格和英文字母构成,不超过100个字符。
输出
单词的个数。
样例输入
stable marriage problem Consists of Matching members
样例输出
7
#include <stdio.h> int main() { int flag=0; //用于标记单词 int num=0; char ch; while((ch=getchar())!='\n') { if(ch==' ') flag=0; //标记 else //出现非空格情况 { if(flag==0) //在属于标记的情况下 { num++; flag=1; //停止标记 } } } printf("%d",num); return 0; }