494 - Kindergarten Counting Game
来源:互联网 发布:松下伺服电机软件 编辑:程序博客网 时间:2024/05/22 10:30
Kindergarten CountingGame
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 andOutput
Input to your program will consist of a series of lines, eachline containing multiple words (at least one). A ``word'' isdefined as a consecutive sequence of letters (upper and/or lowercase).
Your program should output a word count for each line of input.Each word count should be printed on a separate line.
SampleInput
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 ...
SampleOutput
27109
#include <iostream>#include <string>#include <algorithm>//494 Kindergarten Counting Gameusing namespace std;int main(){ string str; int nWords; while(getline(cin,str,'\n')) { nWords = 0; bool isWord =false; string::iterator It; for( It= str.begin(); It!=str.end() ; ++It) { if((*It>='a' && *It<='z') || (*It>='A' && *It <='Z') ) { if(!isWord) isWord = true; } else { if(isWord){ isWord = false; nWords++; } } } --It; //防止最后的字符是字母的情况,不然会少加一; if((*It>='a' && *It<='z') || (*It>='A' && *It <='Z') && isWord) nWords++; cout<<nWords<<endl; }}
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- Kindergarten Counting Game 494
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- 494 - Kindergarten Counting Game
- UVA 494 - Kindergarten Counting Game
- UVA 494 - Kindergarten Counting Game
- uva-494 - Kindergarten Counting Game
- uva 494 - Kindergarten Counting Game
- mysql分区管理 - hash分区
- 网络流
- 怎么查看端口占用情况?
- 固态硬盘测试
- vimrc(带注释)
- 494 - Kindergarten Counting Game
- 寻址(P50)
- CSDN博客编辑器好烂,转去博客园
- S_ISREG等几个常见的宏
- aop(关于事物 的一点点注解)
- USACO A Game解题报告
- k近邻与k-d树
- MyEclipse开发JDBC应用基本过程
- 10420 - List of Conquests