UVa――幼儿园数数游戏(494)

2014-11-24 11:34:50 · 作者: · 浏览: 0

494 - 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
   
    
#include
    
      #include
     
       int main() { int i; int flag,found; int num; char s; while(s!=EOF) { num=0; flag=0; found=0; while((s=getchar())!='\n'&&s!=EOF) { if(!((s>='a'&&s<='z')||(s>='A'&&s<='Z'))) { flag=0; } else if(flag==0) { flag=1; num++; } if(num) found=1; } if(found) printf("%d\n",num); } return 0; } 
     
    
   
这里的return 0 也是至关重要的,我刚开始没有写,就出现了Runing Error的提示。所以初学者多加注意。