首页 > 代码库 > UvaOJ494 - Kindergarten Counting Game

UvaOJ494 - Kindergarten Counting Game



 Kindergarten Counting Game 

Everybody sit down in a circle. Ok. Listen to me carefully.

``Woooooo, you scwewy wabbit!‘‘

Now, could someone tell me how many words I just said?

Input and Output

Input to your program will consist of a series of lines, each line containing multiple words (at least one). A ``word‘‘ is defined as a consecutive sequence of letters (upper and/or lower case).

Your program should output a word count for each line of input. Each word count should be printed on a separate line.

Sample Input

Meep Meep!
I tot I taw a putty tat.
I did! I did! I did taw a putty tat.
Shsssssssssh ... I am hunting wabbits. Heh Heh Heh Heh ...

Sample Output

2
7
10
9
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cctype>
//#define lll
using namespace std;
int main()
{
    #ifdef lll
    freopen("C:\\Documents and Settings\\K70\\桌面\\cin.txt","r",stdin);
    freopen("C:\\Documents and Settings\\K70\\桌面\\out.txt","w",stdout);
    #endif
    char c;
    bool ff=true;
    int  ans=0;
    while((c=getchar())!=EOF)
    {

        if(isalpha(c))
        {
            if(ff)
               {
                   ans++;
                   ff=false;
               }
        }else if(c=='\n')
        {
            printf("%d\n",ans);
            ans=0;
            ff=true;
        }else{
            ff=true;
        }
    }
    return 0;
}


 Kindergarten Counting Game 

Everybody sit down in a circle. Ok. Listen to me carefully.

``Woooooo, you scwewy wabbit!‘‘

Now, could someone tell me how many words I just said?

Input and Output

Input to your program will consist of a series of lines, each line containing multiple words (at least one). A ``word‘‘ is defined as a consecutive sequence of letters (upper and/or lower case).

Your program should output a word count for each line of input. Each word count should be printed on a separate line.

Sample Input

Meep Meep!
I tot I taw a putty tat.
I did! I did! I did taw a putty tat.
Shsssssssssh ... I am hunting wabbits. Heh Heh Heh Heh ...

Sample Output

2
7
10
9