UVA 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

注意:单词的定义是只含字母,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



posted @ 2013-02-26 04:13  WingWing111  阅读(112)  评论(0编辑  收藏  举报