24h購物| | PChome| 登入
2013-03-26 22:12:49| 人氣5,225| 回應1 | 上一篇 | 下一篇

[UVA] 494 - Kindergarten Counting Game

推薦 0 收藏 0 轉貼0 訂閱站台



 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>
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;
}

台長: Morris
人氣(5,225) | 回應(1)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 10633 - Rare Easy Problem
此分類上一篇:[UVA][交集] 737 - Gleaming the Cubes

春藥
很讚的分享~~
2020-02-20 14:01:34
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文