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"stdio.h" #include"string.h" #include"ctype.h" int main() { char s[2500]; int i,n; while(gets(s)!=NULL) {i=1; n=0; while(s[i]) {if(isalpha(s[i-1]))//isaplpha()函数的作用是检查是否为字母; if(!isalpha(s[i])) n++; i++;} printf("%d\n",n); } return 0; }
︶ㄣ人生就像憤怒的小鳥↘當妳失敗時,總有幾頭豬在笑