欢迎访问我的新博客: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. MvcMailer通过ASP.NET MVC Razor视图和基架发送邮件

    MvcMailer是一个有趣的组件,您可以使用ASP.NET MVC框架在发送邮件.很重要的是,它使用Razor视图引擎的观点作为电子邮件模板和很容易安装和使用.在本文中你将看到如何安装,设置邮件模板 ...

  2. iOS开发- 拨打电话总结

    关于iOS应用拨打电话, 我所知道的有3种办法, 详细例如以下: 一.利用openURL(tel) 特点: 直接拨打, 不弹出提示. 而且, 拨打完以后, 留在通讯录中, 不返回到原来的应用. //拨 ...

  3. Bringing up interface eth0: Device eth0 does not seem to be present, delaying initialization

    跑 service network restart  NIC出现无法启动,他说,没有发现 Bringing up interface eth0: Device eth0 does not seem t ...

  4. WebApi路由及版本控制

    public class WebApiControllerSelector : IHttpControllerSelector { private const string NamespaceKey ...

  5. crawler_google工作原理

  6. 浅谈javascript中的call()和apply()方法

    话说在js中,每个函数都包含两个非继承而来的放方法,apply()和call(),使得我们能在特定的作用域中调用函数. 官方定义: 语法:       fun.call(thisArg[, arg1[ ...

  7. 从头开始学JavaScript (八)——变量

    原文:从头开始学JavaScript (八)--变量 一.变量分类: 基本类型值:null.undefined.number.string.Boolean: 引用类型值:保存在内存中的对象,如:Obj ...

  8. 【高德地图API】从零开始学高德JS API(二)地图控件与插件——测距、圆形编辑器、鼠标工具、地图类型切换、鹰眼鱼骨

    原文:[高德地图API]从零开始学高德JS API(二)地图控件与插件——测距.圆形编辑器.鼠标工具.地图类型切换.鹰眼鱼骨 摘要:无论是控件还是插件,都是在一级API接口的基础上,进行二次开发,封装 ...

  9. Swift语言指南(二)--语言基础之注释和分号

    原文:Swift语言指南(二)--语言基础之注释和分号 注释 通过注释向自己的代码中注入不可执行的文本,作为你自己的笔记或提示.Swift编译器运行时会忽略注释. Swift的注释与C语言极其相似,单 ...

  10. Web API 2 对 CORS 的支持

    Web API 2 对 CORS 的支持 CORS概念 跨域资源共享 (CORS) 是一种万维网联合会 (W3C) 规范(通常被认为是 HTML5 的一部分),它可让 JavaScript 克服由浏览 ...