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
27109
C++语言:
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 }