zcmu 1091 统计单词数


 

1091: 统计单词

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

Description

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

Input

见sample

Output

见sample

Sample Input

3 Every night in my dreams I see you I feel you That is how I know you go on

Sample Output

5 6 8




#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;
}


添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值