Description
Everybody sit down in a circle. Ok. Listen to me carefully.
大家做一圈並仔細聽好
“Woooooo, you scwewy wabbit!”
“Woooooo, you scwewy wabbit!”
Now, could someone tell me how many words I just said?
現在,有人能告訴我我剛剛說了多少字?
Input
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).
程式的輸入將包含好幾行,每行包含多個單字(至少一個單字)。“單字”被定義為一連串的字母(大小寫均可)。
Output
Your program should output a word count for each line of input. Each word count should be printed on a separate line.
你的程式應該對每行輸入輸出單字的數量。每筆輸出都應該印在單獨一行上。
Sample Input 1
Sample Input 2
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 ...
Hello,Hello.a
Sample Output 1
Sample Output 2
2
7
10
9
3
Hint
The spacing between words may be other symbols or numbers.
字與字的間格不一定是空白,也可能是其他符號或是數字。
//https://github.com/morris821028/UVa/blob/master/volume004/494%20-%20Kindergarten%20Counting%20Game.cpp
#include<stdio.h>
int main() {
char s[1001];
while(gets(s)) {
int i, flag = 0, count = 0;
for(i = 0; s[i]; i++) {
if((s[i] >= 'A' && s[i] <= 'Z') ||
(s[i] >= 'a' && s[i] <= 'z'))
flag = 1;
else {
count += flag;
flag = 0;
}
}
count += flag;
printf("%d\\n", count);
}
return 0;
}