#include <stdio.h>
int main()
{
printf("输入一行字符:\n");
char ch;
int i,count=0,word=0;
while((ch=getchar())!='\n')
if(ch==' ')
word=0;
else if(word==0)
{
word=1;
count++;
}
printf("总共有 %d 个单词\n",count);
return 0;
}
这个思维方式值得学习一下,首先只要前面是空
格,Word便一直为零,后来遇到第一个字母,
便变为1,这个1不结束就是一个单词,
直到遇到空格,他就又变为0;
然后继续统计后续第一个字母
2020-12-21
最新推荐文章于 2020-12-26 19:38:18 发布

2072

被折叠的 条评论
为什么被折叠?



