c++|逻辑简单,注释完全
简单错误记录
http://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
#include<bits/stdc++.h>
using namespace std;
int main() {
string str;
vector<string> arr; // 存放filename + ' ' + row
map<string, int> dict; // 存放错误记录的count
while (getline(cin, str)) {
reverse(str.begin(), str.end()); // 读取行输入,翻转,好处理很多
stringstream ss(str); // 为了下面使用getline函数,将str转换成输入流
string row;
ss >> row;
reverse(row.begin(), row.end()); // 行数处理完了
// cout << row << endl;
string file_pre;
getline(ss, file_pre, '\\'); // 读取到'\' 获得倒序的完整文件名
// cout << file_pre << endl;
string file = file_pre.substr(1, 16); // 截取倒数16个char
reverse(file.begin(), file.end()); // 翻转回来,文件名处理完了
// cout << file << endl;
string record = file + ' ' + row; // 单条记录
// 新的记录
if (dict.find(record) == dict.end()) {
arr.emplace_back(record);
dict[record] = 1;
}
// 出现过的记录
else
dict[record]++;
}
int i = 0;
if (arr.size() > 8)
i = arr.size() - 8;
for (; i < arr.size(); i++)
cout << arr[i] << ' ' << dict[arr[i]] << endl;
}