题解 | #简单错误记录# 哈希表加队列
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
哈希表加队列
#include <algorithm>
#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
using namespace std;
int main() {
string addr;
int line;
unordered_map<string,int> mp;
queue<string> qstr;
while(cin>>addr>>line){
string temp,temp1;
for(int i=addr.length()-1;i>=0;i--){
if(addr[i]=='\\'){
temp=addr.substr(i+1,addr.length()-i-1);
if(temp.length()>16) temp=temp.substr(temp.length()-16,16);
break;
}
}
string key=temp+' '+to_string(line);
if(mp.find(key)!=mp.end()){
mp[key]+=1;
}
else{
mp[key]=1;
qstr.push(key);
if(qstr.size()>8) qstr.pop();
}
}
while(!qstr.empty()){
string temp;
temp=qstr.front();
qstr.pop();
cout<<temp<<' '<<mp[temp]<<endl;
}
}
// 64 位输出请用 printf("%lld")
#C++#