AcWing 3581. 单词识别
原题链接
简单
作者:
2131-1
,
2023-09-19 19:30:00
,
所有人可见
,
阅读 21
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<cstdlib>
#include<cstdio>
using namespace std;
int cnt[26];
int main(){
string str;
getline(cin,str);
map<string,int> hash;
priority_queue<string,vector<string>,greater<string>> heap;
string tmp="";
for(int i=0;i<str.size();i++){
if(65<=str[i]&&str[i]<=90) str[i] += 'a'-'A';
if(str[i]!=' '&&str[i]!=','&&str[i]!='.') tmp+=str[i];
else{
if(tmp.size()==0) continue;
if(hash[tmp]==0) heap.push(tmp);
hash[tmp]++;
//cout<<tmp<<endl;
tmp.clear();
}
}
if(tmp.size()!=0){
if(hash[tmp]==0) heap.push(tmp);
hash[tmp]++;
}
int n = heap.size();
for(int i=0;i<n;i++){
cout<<heap.top()<<':'<<hash[heap.top()]<<endl;
heap.pop();
}
return 0;
}