UVA oj 494 Kindergarten Counting Game(简单字符串)

原创 2016年06月01日 20:13:45
Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

 Status

Description

Download as PDF

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<cstdio>
#include<iostream>
#include<cstring>

using namespace std;
const int maxn = 1005;
char a[maxn];

int main()
{
    while(gets(a))
    {
        int len = strlen(a);
        int ans = 0;
        int i,j;
       for(i=0;i<len;i++)
       {
           int cnt = 0;
           int flag = 0;
           while((a[i] >= 'a' && a[i] <= 'z') || (a[i] >= 'A' && a[i] <= 'Z') && i < len)
           {
               i++;
               flag = 1;
           }
           if(flag)
           ans++;
       }
       printf("%d\n",ans);
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

uva10815 Andy's First Dictionary(字符串的简单处理)

题目戳这里题意: 按字典序输出文字段落中出现过的所有单词,出现多次记为一次。思路: 1.大写换小写。 2.过滤字母以外字符,生成多个单词,将单词插入到set容器中。 3.使用set容器按字典序...

UVA494判断一个字符串中单词的个数

这题刚开始被省略号迷惑了,刚开始写的 if(s[i]==' '&&s[i+1]!='.') 以及 if(s[i]==' '&&isalpha(s[i+1])) 都WA掉了,却忘记了...

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

494 - Kindergarten Counting Game Everybody sit down in a circle. Ok. Listen to me carefully. `...

UVA 494 Kindergarten Counting Game 单词统计

原题: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem...

UVa494 - Kindergarten Counting Game,java写的

我用java写的,在我的电脑中能运行

UVA oj 445 Marvelous Mazes(水题字符串)

Marvelous Mazes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %l...
  • Sara_YF
  • Sara_YF
  • 2016年06月02日 12:31
  • 145

Uva 11489 - Integer Game 解题报告(简单推理)

Integer Game Two players, S and T, are playing a game where they make alternate moves. S plays fir...
  • kbdwo
  • kbdwo
  • 2014年03月24日 21:12
  • 499

UVA oj 489 Hangman Judge(字符串)

Hangman Judge Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu...
  • Sara_YF
  • Sara_YF
  • 2016年06月02日 15:51
  • 136

UVa 11489 - Integer Game (简单博弈 脑筋急转弯)

I Integer Game     Two players, S and T, are playing a game where they make alte...

Volume 0. Getting Started Uva10055, 10071,10300,458,494,490,414,445,488,489,694,457

刘汝佳 算法入门 第一版
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:UVA oj 494 Kindergarten Counting Game(简单字符串)
举报原因:
原因补充:

(最多只允许输入30个字)