您的位置:首页 > 其它

zcmu 1091 统计单词数

2016-11-17 23:04 211 查看

1091: 统计单词

Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1689  Solved: 757[Submit][Status][Web Board]

Description

输入一个正整数 repeat (0<repeat<10),做repeat 次下列运算:输入一行字符,统计其中单词的个数。各单词之间用空格分隔,空格数可以是多个。

Input

见sample

Output

见sample

Sample Input

3Every night in my dreamsI see you I feel youThat is how I know you go on

Sample Output

568
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cmath>using namespace std;int main(){int repeat,i,flag,counts;char a[105];scanf("%d",&repeat);getchar();while(repeat--){counts=flag=0;gets(a);for(i=0;i<strlen(a);i++){while(a[i]==' ')i++;if(a[i]!=' ')//此处接下面的重点counts++;while(a[i+1]!=' ')i++;}if(a[strlen(a)-1]==' ')//重点,因为在上面的if一句中 不等于空  多加了一次 所以要剪掉counts--;printf("%d\n",counts);}return 0;}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: