Kindergarten Counting Game - UVa494
欢迎访问我的新博客: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的更多相关文章
- 494 - Kindergarten Counting Game
Kindergarten Counting Game Everybody sit down in a circle. Ok. Listen to me carefully. ``Woooooo, ...
- uva494 Kindergarten Counting Game
#include<bits/stdc++.h>using namespace std;int main(){ int n=0; char a; int flag=1; while((sca ...
- UVA 494 Kindergarten Counting Game
题目大意:输入一个字字符串,输出该字符串中所包含的"word"个数,其中"word"是指连续的字母(大小写均可) 题目思路:其实这是道水题,不过我考虑的时候,太 ...
- UVA 494 Kindergarten Counting Game map
Everybody sit down in a circle. Ok. Listen to me carefully.“Woooooo, you scwewy wabbit!”Now, could s ...
- UVA_494:Kindergarten Counting Game
Language: C++ 4.8.2 #include<stdio.h> #include<ctype.h> int main(void) { int ch; int wor ...
- Zerojudge解题经验交流
题号:a001: 哈囉 背景知识:输出语句,while not eof 题号:a002: 簡易加法 背景知识:输出语句,while not eof,加法运算 题号:a003: 兩光法師占卜術 背景知识 ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- 【索引】Volume 0. Getting Started
AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 0. Getting Started 10055 - Hashmat the Brav ...
- UVa OJ 494
Kindergarten Counting Game Everybody sit down in a circle. Ok. Listen to me carefully. ``Woooooo, ...
随机推荐
- Centos7系统配置上的变化(一)
原文 Centos7系统配置上的变化(一) 安装后,一开始有点儿无力吐槽的感觉,变化这么大? 一.Runlevel 首先一条,原来一直用的CentOS-6.5-x86_64-minimal.iso光盘 ...
- interview(转)
http://ifeve.com/ali-think-12/ http://ifeve.com/think-in-ali-10/
- 转让lua性能executeGlobalFunction
没有其他的,搞搞cocos2dx的lua文字,话lua这件事情在几年前学过一段时间.还曾对自己c++介面,我已经做了一些小东西.只是时间的流逝,模糊记忆. 拿起点功夫和成本.下面是我的一些经验. co ...
- int有符号和无符号类型内存 -- C
/* int 有符号 0xffffffff == -1 0xfffffffe == -2 最小 0x80000000 == -21 4748 3648 最大 0x7fffffff == 21 4748 ...
- ReportNG测试报告模板定制
部分参考:http://tech.it168.com/a2013/0906/1530/000001530755_3.shtml ReportNG提供了简单的方式来查看测试结果,并能对结果进行着色, ...
- 各种加密解密函数(URL加密解密、sha1加密解密、des加密解密)
原文:各种加密解密函数(URL加密解密.sha1加密解密.des加密解密) 普通hash函数如md5.sha1.base64等都是不可逆函数.虽然我们利用php可以利用这些函数写出可逆函数来.但是跨语 ...
- [CLR via C#]5.4 对象哈希码和dynamic基元类型
原文:[CLR via C#]5.4 对象哈希码和dynamic基元类型 FCL的设计者认为,如果能将任何对象的任何实例放到一个哈希表集合中,会带来很多好处.为此,System.Object提供了虚方 ...
- WPF中嵌入WinForm中的webbrowser控件
原文:WPF中嵌入WinForm中的webbrowser控件 使用VS2008创建WPF应用程序,需使用webbrowser.从工具箱中添加WPF组件中的webbrowser发现其中有很多属性事件不能 ...
- WCF与Web API 区别
WCF与Web API 区别(应用场景) Web api 主要功能: 支持基于Http verb (GET, POST, PUT, DELETE)的CRUD (create, retrieve, ...
- C语言与sqlserver数据库
原文:C语言与sqlserver数据库 1.使用C语言来操作SQL SERVER数据库,采用ODBC开放式数据库连接进行数据的添加,修改,删除,查询等操作. step1:启动SQLSERVER服务,例 ...