AcWing 3581. 单词识别
原题链接
简单
作者:
ChenRich
,
2025-03-25 10:38:23
·浙江
,
所有人可见
,
阅读 3
屎山代码,不管了,投
#include<bits/stdc++.h>
using namespace std;
int main(){
map<string,int> hash;
string s; getline(cin,s);
s=' '+s;
for(int i =0;i<s.size();i++){
if(s[i]<='Z'&&s[i]>='A'){
s[i]+=32;
}
if(s[i]==','||s[i]=='.'){
s[i]=' ';
}
}
if(s[0]!=' ') s=' '+s;
if(s[s.size()-1]!=' ') s+=' ';
for(int i =0;i<s.size()-1;i++){
string st;
if(s[i]==' '&&s[i+1]!=' '){
int j =i+1;
while(s[j]!=' '){
st+=s[j++];
}
hash[st]++ ;
}
}
for (auto &a : hash) {
cout << a.first << ":" << a.second << endl;
}
return 0;
}