单词数
来源:互联网 发布:python 3.0 廖雪峰 编辑:程序博客网 时间:2024/04/28 13:32
单词数
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 31799 Accepted Submission(s): 7522
Problem Description
lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。
Input
有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。
Output
每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。
Sample Input
you are my friend#
Sample Output
4
Author
#include<iostream>#include<algorithm>#include<cstdio>#include<set>#include<sstream>using namespace std;int main() {set<string> article;//定义一个string类型的容器articlestring word;//定义一个word字符串while(getline(cin,word)&&word[0]!='#')//getline(cin,str,'#');最后一个是结束字符标志,不知道为什么这么用就错了!{stringstream ss(word);//定义一个数据流string buf;while(ss>>buf)//遇到空格结束article.insert(buf);//插入,相同的字符串就不插入了,这就是set容器的优点cout << article.size() << endl;//读出set的长度ss.str("");//释放str的内存!article.clear();//清空容器!}return 0;}看看stringstream的特点!
#include<iostream>#include<algorithm>#include<cstdio>#include<set>#include<sstream>using namespace std;int main(){ string str; getline(cin,str,'#'); stringstream ss(str); string buf; ss>>buf; cout<<buf; ss.str("");}遇到空格结束,正好满足读取单词的特点!
0 0
- 数单词
- 单词数
- 单词数
- 数单词
- 单词数
- 单词数
- 单词数
- 单词数
- 单词数
- 单词数
- 单词数
- 单词数
- 单词数
- 单词数
- 单词数
- 单词数
- 单词数
- 单词数
- iOS 进阶知识(框架)
- MFC中用到的c++基本数据类型
- 机器学习:回归 梯度下降法
- PHP把excel(xls)文件数据导入mysql数据库
- Quick cocos2dx-Lua(V3.3R1)学习笔记(6)---- 让精灵执行不同的动作
- 单词数
- socket read浅析
- Google Protobuf 协议分析
- 结构数组,结构数组类型(typedef)
- github命令大全
- OC中的NSArray
- aix 命令:lsdev、lsattr、lscfg
- Collections.sort in JDK6:MergeSort
- CentOS7部署php+apache+oracle