题解 | #简单错误记录#
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
#include <iostream>
#include <iterator>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <queue>
using namespace std;
int main(int argc, char* argv[]){
string str;
unordered_map<string, int> dic;
queue<string> que;
while(getline(cin, str)){
string::reverse_iterator name_start = find(str.rbegin(), str.rend(), '\\');
string::iterator name_end = find(str.begin(), str.end(), ' ');
int dist = distance(name_start.base(), name_end);
if(dist > 16){
int start_index = distance(str.begin(), name_end-16);
int length = distance(name_end-16, str.end());
str = str.substr(start_index, length);
}
else{
int start_index = distance(str.begin(), name_start.base());
int length = distance(name_start.base(), str.end());
str = str.substr(start_index, length);
}
if(!dic.count(str)){
que.push(str);
}
++dic[str];
}
int n = que.size();
while(n > 8){
que.pop();
--n;
}
while(!que.empty()){
cout << que.front() << " " << dic[que.front()] << endl;
que.pop();
}
return 0;
}