`
hellobin
  • 浏览: 62722 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

UVA 494 Kindergarten Counting Game

    博客分类:
  • UVA
 
阅读更多

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

注意:单词的定义是只含字母,a...a是2个单词



#define RUN
#ifdef RUN

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <cctype> 
#include <algorithm>
#include <utility>
#include <math.h>

using namespace std;

#define MAXN 1000


int main(){


#ifndef ONLINE_JUDGE
	freopen("494.in", "r", stdin);
	freopen("494.out", "w", stdout); 
#endif

	char c;
	int cnt = 0;
	bool isword = false;

	while(scanf("%c", &c) != EOF){
		if(c == '\n'){
			if(isword){
				cnt++;
			}
			printf("%d\n", cnt);
			cnt = 0;
			continue;
		}
		
		if(isalpha(c)){
			isword = true;
		}
		if(!isalpha(c) && isword){
			cnt++;
			isword = false;
		}
	}
	


	
	
}


#endif


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics