循环-06. 统计一行文本的单词个数(15)

来源:互联网 发布:逗斗车 知乎 编辑:程序博客网 时间:2024/05/19 00:40

本题目要求编写程序统计一行字符中单词的个数。所谓“单词”是指连续不含空格的字符串,各单词之间用空格分隔,空格数可以是多个。

输入格式:

输入给出一行字符。

输出格式:

在一行中输出单词个数。

输入样例:
Let's go to room 209.
输出样例:
5
#include<stdio.h>#include<ctype.h>int main(void){char ch;int n=0,inword=0;do{ch=getchar();if(!isspace(ch)&&(inword==0)){n++;inword=1;}if(isspace(ch)&&(inword==1))inword=0;}while(ch!='\n');printf("%d",n);return 0;}


0 0