题解 | #简单错误记录#
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
//使用两个map,map<string,int>储存次数,map<int,string>储存顺序 #include<iostream> #include<map> #include<string> using namespace std; string itos(int x) { string str="",str0=" "; while(x!=0) { str0[0]=x%10+48; str=str0+str; x=x/10; } return str; } int main() { map<string,int> map_s; map<int,string> map_n; int x,n=0; string str; while(cin>>str>>x) { for(int i=0;i<str.size();) { if(str[i]!='\\') { i++; } else { str.erase(0,i+1); i=0; } } if(str.size()>16) { str.erase(0,str.size()-16); } str=str+" "+itos(x); if(!map_s[str]) { map_s[str]=1; n++; map_n[n]=str; } else { map_s[str]++; } } int t=1; if(map_n.size()>8) { t=map_n.size()-7; } for(int i=t;i<=map_n.size();i++) { cout<<map_n[i]<<" "<<map_s[map_n[i]]<<endl; } return 0; }