单词统计

单词统计

1000ms
65536KB
64-bit integer IO format: %lld      Java class name: Main
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;
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值