[YTU]_2002(C语言实验——单词统计)

来源:互联网 发布:易娱网络怎么样 编辑:程序博客网 时间:2024/06/13 04:34

Description

从键盘输入一行字符,统计其中单词的个数,各单词以空格分隔,且空格数可以是多个。

Input

输入只有一行句子。仅有空格和英文字母构成。

Output

单词的个数。

Sample Input

stable marriage  problem Consists     of Matching members

Sample Output

7
#include <iostream>#include <cstring>using namespace std;int main(){    char str[100];    int n=0,i;    gets(str);    for(i=0;str[i]!='\0';i++)    {        if(str[i]!=' '&&str[i+1]==' ')            n++;    }        cout<<n+1<<endl;    return 0;}

原创粉丝点击