uvaRoot :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 0. Getting StartedSubmit Do
来源:互联网 发布:编程公司 编辑:程序博客网 时间:2024/06/10 08:34
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 ona 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
wa:#include <iostream>#include <cstdio>#include <string>#include <cstring>using namespace std;const int MAXN = 205;string s;char ch, a;bool is(char ch){ return ('a'<=ch&&ch<='z' || 'A'<=ch&&ch<='Z');}int main(){ //freopen("input.txt", "r", stdin); while(getline(cin , s)) { int cnt = 0; int len = s.length(); for(int i = 0; i<len-1; i++) { if(s[i] == ' ') { while(s[i+1] == ' ') i++; if(is(s[i+1])) cnt++; } } printf("%d\n", cnt+1); } return 0;}#include <iostream>#include <cstdio>#include <string>#include <cstring>using namespace std;const int MAXN = 205;string s;char ch, a;bool is_zimu(char ch){ return ('a'<=ch&&ch<='z' || 'A'<=ch&&ch<='Z');}bool is(string s){ int len = s.length(); for(int i = 0; i< len; i++) { if(is_zimu(s[i])) return true; } return false;}int main(){ //freopen("input.txt", "r", stdin); int cnt = 0; while((ch = getchar()) != EOF) { if(ch == '\n') { if(is(s)) { cnt++; } printf("%d\n", cnt); s.clear(); cnt = 0;continue; } if(ch == ' ') { if(is(s)) { cnt++; } s.clear();continue; } s += ch; } return 0;}终于ac,其实想到了好的方法几行代码就ok,否则真是没办法啊#include <iostream>#include <cstdio>#include <string>#include <cstring>using namespace std;const int MAXN = 205;string s;char ch, a;int cnt = 0;bool is_zimu(char ch){ return ('a'<=ch&&ch<='z' || 'A'<=ch&&ch<='Z');}int main(){ //freopen("input.txt", "r", stdin); while(getline(cin, s)) { int len = s.length(); for(int i = 0; i < len-1; i++) { if(is_zimu(s[i])) { while(is_zimu(s[i])) { i++; } cnt++; } } printf("%d\n", cnt); cnt = 0; } return 0;}#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <cctype>//发现了一个好头文件,可以将用来判断字母using namespace std;const int MAXN = 205;string s;char ch, a;int cnt = 0;/*bool is_zimu(char ch){ return ('a'<=ch&&ch<='z' || 'A'<=ch&&ch<='Z');}*/int main(){ freopen("input.txt", "r", stdin); while(getline(cin, s)) { int len = s.length(); for(int i = 0; i < len-1; i++) { if(isalpha(s[i]))//判断是否是字母,不用自己写判断函数了 { while(isalpha(s[i])) { i++; } cnt++; } } printf("%d\n", cnt); cnt = 0; } return 0;}
0 0
- uvaRoot :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 0. Getting StartedSubmit Do
- Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 0. Getting Started 488 -
- AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 0. Getting Started
- 【索引】AOAPC I: Beginning Algorithm Contests (Rujia Liu)
- 【索引】AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu)
- 【索引】AOAPC I: Beginning Algorithm Contests (Rujia Liu)
- 【索引】 AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu)
- [索引] AOAPC I: Beginning Algorithm Contests (Rujia Liu)
- 【索引】AOAPC I: Beginning Algorithm Contests (Rujia Liu)
- [索引]AOAPC I: Beginning Algorithm Contests (Rujia Liu)
- 【索引】AOAPC I: Beginning Algorithm Contests (Rujia Liu)
- 【索引】AOAPC I: Beginning Algorithm Contests (Rujia Liu)
- 【索引】AOAPC I: Beginning Algorithm Contests (Rujia Liu)
- 【索引】 AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu)
- 02_UVaOJ_ AOAPC I_Beginning Algorithm Contests (Rujia Liu)_Volume0_Getting Started
- UVa-Beginning Algorithm Contests
- 【索引】Volume 0. Getting Started
- 【索引】Volume 0. Getting Started
- Android从入门到精通第9章:图形图像处理技术
- VB.net版机房人重构中的结账之音符
- 面向对象数据库:Ndatabase使用注意
- 新浪实时股票数据接口
- LKDBHelper 数据库位置
- uvaRoot :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 0. Getting StartedSubmit Do
- 3DMax二次开发的配置
- Ubuntu-下载工具--uget+aria2
- 多个div水平排列并出现横向滚动条
- 贪心法——区间的最大覆盖数
- 最小数字
- 简单的电子词典 因手机问题未图
- 第13周项目5-字符统计之字母个数
- hdu 5125 magic balls LIS (dp+树状数组优化)