UVa 494 - Kindergarten Counting Game

Contents

  1. 1. Problem
  2. 2. Solution
  3. 3. Code

Problem

中文網址

Solution

處理符號和空白那些,記得每行最後一個單字也要算到。

Code

UVa 494
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<cstdio>
#include<cctype>

int main()
{
char c;
int count(0);
bool flag(false);

while ((c = getchar()) != EOF)
{
if (c == '\n')
{
if (flag)
count++;
printf("%d\n", count);

count = 0;
flag = false;
continue;
}

if (isalpha(c))
{
if (!flag)
flag = true;
}
else if (flag)
{
count++;
flag = false;
}

}

return 0;
}