单词统计
2013-08-27 10:38
155 查看
单词统计
Time Limit: 1000msMemory Limit: 65536KB
64-bit integer IO format:
%lld Java class name: Main
Prev
Submit
Status
Statistics
Discuss
Next
Font Size:
现在有一段文本需要处理,需要你编写一个小程序,能够读取文本中的所有内容,把其中出现的每个单词的统计出来,最后输出满足要求的单词。一个单词由一段连续的英文字母组成,单词与单词之间由一个或多个空格、tab或回车分隔。单词在统计个数时不区分大小写。
Input
输入是一段英文文章。英文文章的单词数不超过2000.每个单词的长度不超过25。Output
输出所有出现次数大于或等于3次的单词,每个单词一行。单词以全小写方式输出。 单词按字典序,从小到大输出。(字典序表示两个单词字符串调用strcmp比较所得到的大小顺序)。 如果实际满足要求的单词没有,则输出一个无内容的文件。 如果实际满足要求的单词数超过10个,则输出字典序前10个单词。Sample Input
Beijing Normal University has a history of more than one hundred years which is almost as long as the history of Chinese modern education Beijing Normal University has developed from the Faculty of Education Capital Metropolitan University established under the concept of Establish school prioritize teacher education which initiated teacher training in Chinese higher education After several times of merging and reforming especially Beijing Normal University has moved into the new age of rapid development Beijing Normal University history is an epitome of the development of modern teacher training and Chinese higher education
Sample Output
beijing chinese education has history normal of teacher the university 容器无敌啊!
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<map> #include<algorithm> #include<vector> using namespace std; int min(int a,int b) { return a<b?a:b; } int main() { int i; map<string,int>mp; vector<string>vec; char str[33]; mp.clear(); while(scanf("%s",str)!=EOF) { int n = strlen(str); for(i=0;i<n;i++) { str[i]=tolower(str[i]); } mp[str]++; if(mp[str]==3) { vec.push_back(str); } } sort(vec.begin(),vec.end()); for(i=0;i<min(vec.size(),10);i++) { cout<<vec[i].c_str()<<endl; } return 0; }
相关文章推荐
- 统计字符串中每个单词出现的次数 for C++
- HashMap分拣存储2:统计每个单词出现的次数(采用面向对象)
- java统计文本中英文单词个数
- 17.2统计单词个数
- 单词统计
- 实验四-1 统计文本单词的个数
- 统计单词数目的脚本
- c++实现文本中英文单词和汉字字符的统计
- Trie树统计单词前缀
- 使用Java统计英文文章的单词频率。
- 关于MapReduce单词统计的例子:
- SPark单词统计
- 第四章实验:统计文本单词的个数
- Java 中实现文章单词,标点的统计办法。
- Vector实现统计输入单词的个数
- MR英语单词频次统计案例-----wordcount
- C++第17周项目7——用程序玩文件(1)统计单词数
- C++之单词统计
- Java实现统计一篇文章中每个单词出现的次数
- Linux下统计文本文件中前n个出现频率最高的单词