题解 | #简单错误记录#
简单错误记录
http://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <deque>
using namespace std;
int main() {
string str;
map<string,int> m;
deque<string> dq;
while(getline(cin,str)){
str+=' ';
vector<string> v;
string temp;
size_t nprev=0;
size_t n = str.find(' ');
temp = str.substr(0,n);
v.push_back(temp);
nprev=n;
n=str.find(' ',nprev+1);
temp = str.substr(nprev+1,n-nprev-1);
v.push_back(temp);
size_t x = v[0].find_last_of('\\');
temp = v[0].substr(x+1);
if((v[0].size()-x-1)>16){
temp=v[0].substr(v[0].size()-16);
}
temp+=' '+v[1];
if(m.find(temp)==m.end()) dq.push_back(temp);
++m[temp];
if(dq.size()>8) dq.pop_front();
}
for(auto &it:dq){
cout<<it<<' '<<m[it]<<endl;
}
}