#include <iostream> #include <string> #include <vector> #include <algorithm> #include <map> using namespace std; struct ErrInfo { string fileName; string lineNum; int count; }; int main() { map<string, ErrInfo> dict; vector<string> stringList; string line; while (getline(cin, line)) { if (line.empty()) break; stringList.push_back(line); } vector<string> keys; for (string l : stringList) { // 得到行号 从 右往左找 int spaceIndex = l.rfind(' '); string lineNum = l.substr(spaceIndex + 1); // 获取路径从 前到空格位置 string path = l.substr(0, spaceIndex); // 获取文件名 int index = path.rfind('\\'); string name = path.substr(index + 1); int length = name.size(); if (length > 16) name = name.substr(length - 16); // 放入map中 string key = name + " " + lineNum; auto it = find(keys.begin(), keys.end(), key); // 没找到就插入数组中,不插入重复的; if (it == keys.end()) keys.push_back(key); if (dict.find(key) != dict.end()) { // 存在相同的 dict[key].count++; } else { dict[key].count = 1; } } int i = keys.size() <= 8 ? 0 : keys.size() - 8; for (; i < keys.size(); i++) { ErrInfo info = dict.at(keys[i]); cout << keys[i]; cout << " "; cout << info.count; cout << endl; } return 0; }