1133: 单词个数统计

来源:互联网 发布:webrtc 源码介绍 编辑:程序博客网 时间:2024/06/05 18:19

Description

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

Input

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

Output

单词的个数 

Sample Input

stable marriage problem Consists of Matching members

Sample Output

7

HINT

Source

#include <stdio.h>#include <stdlib.h>//统计单词个数,有多个空格int main(){    char str[1000];    int i=0,count=0;    gets(str);    if(str[0]!=' ') count=1;    for(i=1; str[i]!='\0'; i++)    {        if(str[i-1]==' '&& str[i]!=' ')            count++;    }    printf("%d\n",count);    return 0;}