判断出现次数高频率词汇

#include <bits/stdc++.h> 
using namespace std;
int main(){
    string a;
    map<string,int> m;
    vector<string> lm;
    
    while(cin>>a){
        for(int i=0;i<a.size();i++){
            
            a[i]=tolower(a[i]);
            if(a[i]<'a' ||a[i]>'z'){
                a=a.substr(0,i);
            }
        }
        if(m[a]==0){
            lm.push_back(a);
        }
        m[a]++;
        
    }
    int _max=0;
    string cc;
    
    for(auto c:lm){
        if(m[c]>=_max){
            cc=c;
        }
        _max=max(_max,m[c]);
        cout<<c<<":"<<m[c]<<endl;
    }
    cout<<"高频词汇:"<<cc<<":"<<_max<<endl;
    return 0;
}

 

posted @ 2025-05-31 15:58  -刘-j-x-  阅读(6)  评论(0)    收藏  举报