题解 | #简单错误记录#
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
#include <iostream> #include <map> #include <sstream> #include <string> #include <vector> #include <queue> using namespace std; string seg(string input){ istringstream iss(input); vector<string> tmp; vector<string> T; string temp; while(getline(iss, temp, ' ')){ T.push_back(temp); } istringstream is(T[0]); while(getline(is, temp, '\\')){ tmp.push_back(temp); } if(tmp.back().length() >= 16){ temp = tmp.back().substr(tmp.back().length() - 16) + ' ' + T[1]; } else{ temp = tmp.back() + ' ' + T[1]; } return temp; } int main() { // string m; // getline(cin, m); // string x = seg(m); // cout << x; string input; map<string, int> result; vector<string> res; while(getline(cin, input)){ string m = seg(input); result[m]++; if(res.size() == 0){ res.push_back(m); } else{ auto i = res.begin(); int flag = 0; while(i <= res.end()){ if(*i == m){ flag = 1; break; } else{ i++; } } if(flag == 0){ res.push_back(m); } } } int n = res.size(); int start = 0; if(n > 8){ start = n - 8; } while(start < n){ for(auto val : result){ if(val.first == res[start]){ cout << res[start] << ' ' << val.second << endl; start++; } } } return 0; }