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, ...
随机推荐
- SVN在branch兼并和游戏patch(1)
近期要hadoop2.4关于上面的行hdfs raid,但在此之前hdfs raid如svn 的branch发展,领导人希望patch方式hdfs raid功能进球trunk里面去,这里涉及到svn ...
- Python challenge 3 - urllib & re
第三个主题地址:http://www.pythonchallenge.com/pc/def/ocr.html Hint1:recognize the characters. maybe they ar ...
- c语言获取符号位整数和浮点
1. 为什么你应该得到的签位 非常多的时间,我们需要推断的数目值正和负,做了相应的逻辑处理.完成这一要求条件推断语句可以很好. 有时会出现以下情况, if (x > 0) { x = x - 1 ...
- Hadoop之——CentOS构造ssh否password登录注意事项
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46388809 前提配置:使用root登录改动配置文件:/etc/ssh/sshd_ ...
- Codeforces 10C Digital Root 法冠军
主题链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<se ...
- linux_增加用户组_删除用户
添加账号组 /usr/sbin/groupadd iknow 添加账号 /usr/sbin/useradd -g iknow -d /home/iknow/ iknow 更改密码 passwd 选项 ...
- HTML DOCTYPE 重要性
定义和使用方法 <!DOCTYPE> 声明必须是 HTML 文档的第一行.位于 <html> 标签之前. <!DOCTYPE> 声明不是 HTML 标签.它是指示 ...
- IIS7伪静态化URL Rewrite模块
原文 IIS7伪静态化URL Rewrite模块 在Win7安装了IIS7.5之后,搭建一些网站或者博客,但是IIS7.5本身没有URL Rewrite功能,也就是无法实现网址的伪静态化. 从网上找了 ...
- asp.net mvc3 的数据验证(一)
原文:asp.net mvc3 的数据验证(一) 对于web开发人员来说,对用户输入的信息进行验证是一个重要但是繁琐的工作,而且很多开发者都会忽略.asp.net mvc3框架使用的是叫做“ ...
- Hibernat之关系的处理一对一处理
第一步:编写两个pojo,比如一个学生表一个班级表 这里使用注解. 需要 公司表: package com.qcf.pox; import javax.persistence.CascadeType ...