题解 | #简单错误记录#
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;
map<pair<string, string>, int> elog;
vector<pair<string, string>> log_out; // 按顺序记录出现的错误
void RecordError(pair<string, string> key) {
if(elog.count(key)) { // 错误记录已存在
elog[key]++;
}
else {
elog[key] = 1;
log_out.push_back(key);
}
}
int main() {
string input;
while(getline(cin, input)) {
pair<string, string> err_key; // <文件名,行数>
int fname_begin = input.find_last_of('\\') + 1;
int fname_end = input.find_first_of(' ');
if(fname_end - fname_begin > 16)
err_key.first = input.substr(fname_end - 16, 16);
else
err_key.first = input.substr(fname_begin, fname_end - fname_begin);
err_key.second = input.substr(fname_end + 1);
RecordError(err_key);
}
int start_pos = log_out.size() > 8 ? log_out.size()-8 : 0;
for(int i=start_pos; i<log_out.size(); ++i) {
cout << log_out[i].first << ' ' << log_out[i].second << ' ' << elog[log_out[i]] << endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")


