您的位置:首页 > 其它

单词统计

2013-08-27 10:38 155 查看

单词统计

Time Limit: 1000ms
Memory 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;
}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  单词统计