题解 | #简单错误记录# 利用数据结构
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
#include <iostream> #include <queue> #include <set> #include <map> using namespace std; int main() { string s; queue<string> errors; set<string> se; map<string, int> mp; while (getline(cin, s)) { char a = '\\'; int r = s.rfind(a), len = s.size(), blank = 0; for (int i = r + 1; i < len; i++) { if (s[i] == ' ') { blank = i; break; } } string name = s.substr(r + 1, blank - r - 1); int name_len = name.size(); if (name_len > 16) { name = name.substr(name_len - 16, 16); } name += s.substr(blank); if (se.find(name) == se.end()) { se.insert(name); mp[name] = 1; if (errors.size() < 8) { errors.push(name); } else if (errors.size() == 8) { errors.pop(); errors.push(name); } } else { mp[name]++; } } while (!errors.empty()) { cout << errors.front() << " " << mp[errors.front()] << endl; errors.pop(); } return 0; } // 64 位输出请用 printf("%lld")