Kindergarten Counting Game - UVa494
来源:互联网 发布:金灿榕网络 编辑:程序博客网 时间:2024/05/22 03:40
欢迎访问我的新博客: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
27109
解题思路
这个题目要统计每行中的单词数目。
注意对输入的处理。
使用了一个状态标志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;}
(全文完)
0 0
- uva494 Kindergarten Counting Game
- UVa494 Kindergarten Counting Game
- Kindergarten Counting Game - UVa494
- UVA494 Kindergarten Counting Game
- UVA494 - Kindergarten Counting Game
- UVa494 - Kindergarten Counting Game-难度1
- UVa494 - Kindergarten Counting Game,java写的
- 算法竞赛入门经典-前四章-UVa494 - Kindergarten Counting Game-幼儿园数数游戏-难度1
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 高级数组,实现特定值的插入、查找、删除等操作
- NYOJ 236 心急的C小加
- xml 使用PULL解析器
- 认识DOM的三大节点:元素节点,文本节点,属性节点以及nodeName,nodeType,nodeValue的区别
- php替换数组内元素
- Kindergarten Counting Game - UVa494
- NYOJ 364 田忌赛马
- OC各种数据类型之间的转换方法
- 红帽把云未来押注在OpenStack上
- 大尺寸的瓷砖加工技术突破
- 映射类型 字典 (python)
- O(n) 求 最长回文子串
- Android NDK开发篇(一):新版NDK环境搭建(免Cygwin,超级快)
- Cocos2d-x Protobuf 的使用