【UVA - 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
1 // Project name : D ( Kindergarten Counting Game ) 2 // File name : main.cpp 3 // Author : Izumu 4 // Date & Time : Tue Jul 10 19:40:52 2012 5 6 7 #include <stdio.h> 8 #include <ctype.h> 9 #include <string.h> 10 #define N 10000 11 12 char a[N]; 13 14 int main() 15 { 16 int n; 17 18 while(gets(a)!=NULL) 19 { 20 n=strlen(a); 21 int found,count=0; 22 for(int i=0;i<n;i++) 23 { 24 if(isalpha(a[i])) found=1; 25 else{ 26 if(found) count++; 27 found =0; 28 } 29 30 31 } 32 printf("%d\n",count); 33 34 } 35 return 0; 36 } 37 38 39 // end 40 // ism