欢迎访问我的新博客:http://www.milkcu.com/blog/

原文地址:http://www.milkcu.com/blog/archives/uva494.html

题目描述

 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

解题思路

这个题目要统计每行中的单词数目。

注意对输入的处理。

使用了一个状态标志state:

state为1表示上一字符在单词内;

state为0表示上一字符不在单词内。

代码实现

#include <stdio.h>
int isl(char c) {
if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
return 1;
} else {
return 0;
}
}
int main(void) {
char s[100000];
int rear = 0;
int c;
while((c = getchar()) != EOF) {
s[rear++] = c;
}
s[rear] = '\0';
int i = 0;
int num = 0;
int state = 0;
while(s[i] != '\0') {
if(s[i] == '\n') {
printf("%d\n", num);
num = 0;
state = 0;
} else {
if(isl(s[i])) {
if(state == 0) {
num++;
}
state = 1;
} else {
state = 0;
}
}
i++;
}
return 0;
}

(全文完)

Kindergarten Counting Game - UVa494的更多相关文章

  1. 494 - Kindergarten Counting Game

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

  2. uva494 Kindergarten Counting Game

    #include<bits/stdc++.h>using namespace std;int main(){ int n=0; char a; int flag=1; while((sca ...

  3. UVA 494 Kindergarten Counting Game

    题目大意:输入一个字字符串,输出该字符串中所包含的"word"个数,其中"word"是指连续的字母(大小写均可) 题目思路:其实这是道水题,不过我考虑的时候,太 ...

  4. UVA 494 Kindergarten Counting Game map

    Everybody sit down in a circle. Ok. Listen to me carefully.“Woooooo, you scwewy wabbit!”Now, could s ...

  5. UVA_494:Kindergarten Counting Game

    Language: C++ 4.8.2 #include<stdio.h> #include<ctype.h> int main(void) { int ch; int wor ...

  6. Zerojudge解题经验交流

    题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...

  7. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  8. 【索引】Volume 0. Getting Started

    AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 0. Getting Started 10055 - Hashmat the Brav ...

  9. UVa OJ 494

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

随机推荐

  1. asp.net下cookie 的基础使用

    cookie作为在B/S开发中经常被使用到的东西,asp.net必然提供了现成的东西给我们使用. 就是这个对象:HttpCookie,当然了,对于asp.net来说,Request和Response中 ...

  2. mac 配置Python集成开发环境

    mac 配置Python集成开发环境(Eclipse +Python+Pydev) 1.下载Mac版64位的Eclipse. 进入到Eclipse官方网站的下载页面(http://www.eclips ...

  3. javascript利用map,every,filter,some,reduce,sort对数组进行最优化处理

    案例: var scoresTable=[ {id:11,name:"小张",score:80}, {id:22,name:"小王",score:95}, {i ...

  4. hdu1881 毕业bg(深搜索dfs)

    主题链接:pid=1881">http://acm.hdu.edu.cn/showproblem.php? pid=1881 ----------------------------- ...

  5. 完整详细的说明GCD列(一)dispatch_async;dispatch_sync;dispatch_async_f;dispatch_sync_f

    为什么要写这个系列,由于百度了一下.我们正在寻找一个非常比较片面的Blog.抄来抄去,写作是很粗糙. 所以,我想写这个系列,尝试记录官方网站GCD强大的全功能的表达.为了方便他们,也方便他人,假设有发 ...

  6. Android_显示器本身被卸载应用程序

    1.经jni实现功能 //LOG宏定义 #define LOG_INFO(tag, msg) __android_log_write(ANDROID_LOG_INFO, tag, msg) #defi ...

  7. 【转】Uiautomator Api浅析

    原文地址:http://blog.sina.com.cn/s/blog_ae2575ff01018b2o.html uiautomator api: http://android.toolib.net ...

  8. hbase ganglia监控配置

    hbase ganglia 显示器 hbase 构造 hadoop-metrics2-hbase.properties *.sink.ganglia.class=org.apache.hadoop.m ...

  9. [CLR via C#]1.6 Framework类库~1.9与非托管代码的互操作性

    原文:[CLR via C#]1.6 Framework类库~1.9与非托管代码的互操作性 1.6 Framework类库 1. .NET Framework中包含了Framework类库(Frame ...

  10. [Unity3D]Unity3D连衣裙实现游戏开发系统

    大家好,我是秦培.欢迎关注我的博客,我的博客地址">blog.csdn.net/qinyuanpei. 不知从什么时候開始,国产RPG单机游戏開始出现换装,仙剑系列中第一部实现了换装的 ...