494 - 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

C++语言: Codee#23767
01 #include <iostream>
02 #include <cstdio>
03 using namespace std;
04
05 int main()
06 {
07     int cnt = 0;
08     int inword=0;
09     for(char c; (c = getchar()) != EOF;)
10         if(isalpha(c))
11          inword=1;
12          else if('\n' == c)
13         {
14             printf("%d\n", cnt + inword);
15             cnt = 0;
16             inword=0;
17         }
18          else if(inword)
19          {
20             ++cnt;
21             inword=0;
22          }
23
24     return 0;
25 }
posted @ 2011-11-04 23:47  strorehouse  阅读(315)  评论(0编辑  收藏  举报