题解 | #简单错误记录#
简单错误记录
http://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
20 行解决问题
- deque存储结果
- map解决相同
#include <iostream> #include <unordered_map> #include <deque> using namespace std; int main() { string path, num; unordered_map<string, int> hash; deque<string> logQue; while (cin >> path >> num) { string fileName = path.substr(path.rfind("\\") + 1); if (fileName.size() > 16) fileName = fileName.substr(fileName.size() - 16); string loginfo = fileName + ' ' + num; if (hash.count(loginfo)) ++hash[loginfo]; else { hash[loginfo] = 1; logQue.push_back(loginfo); if (logQue.size() > 8) logQue.pop_front(); } } while (!logQue.empty()) { cout << logQue.front() << " " << hash[logQue.front()] << endl; logQue.pop_front(); } return 0; }