ZZULIOJ 1133: 单词个数统计

题目描述从键盘输入一行字符,长度小于1000。统计其中单词的个数,各单词以空格分隔,且空格数可以是多个。
输入输入只有一行句子。仅有空格和英文字母构成

输出单词的个数

样例输入stable marriage problem Consists of Matching members

样例输出7

#include<stdio.h>
int main(){
 char a[1000];
 int i,num=0,word=0;
 char c;
 gets(a);
 for(i=0;(c=a[i])!='\0';i++)
 if(c==' ')word=0;                //空格作为将出现新单词的标识
 else if(word==0){
  word=1;
  num++;
 }
 printf("%d",num);
 return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43731933/article/details/84309838