题解 | 简单错误记录

#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;

string getFileName(string path)
{
    int nPos = path.find_last_of('\\') + 1;
    string fileName = path.substr(nPos, path.length()-nPos);
    if (fileName.length() > 16) {
        fileName = fileName.substr(fileName.length()-16, 16);
    }
    return fileName;
}

string toNewInfo(string info) {
    stringstream ss(info);
    string newInfo;
    for (int i=0; i<2; i++) {
        string a;
        if (getline(ss, a, ' ')) {
            if (0 == i) {
                newInfo = getFileName(a);
            } else {
                newInfo += " ";
                newInfo += a;
            }
        }
    }
    return newInfo;
}

int main() {
    string a;
    map<string, int> logMap;
    vector<string> logVec;
    map<string, int>::iterator iter;
    while (getline(cin, a)) {
        string log = toNewInfo(a);
        iter = logMap.find(log);
        if (iter != logMap.end()) {
            iter->second += 1;
        } else {
            logMap.insert(make_pair(log, 1));
            logVec.push_back(log);
        }
    }

    while (logVec.size() > 8) {
        logVec.erase(logVec.begin());
    }
    for (auto log: logVec) {
        iter = logMap.find(log);
        cout << log << " " << iter->second << endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

03-26 22:55
门头沟学院 Java
烤冷面在迎接:河南byd,应该就是郑大了。不过24届计算机是特殊情况,那年除了九✌和强2,以及两三个关系够硬的双非,其他的都是炮灰,感觉是十几年来互联网行业最烂的一年,如果想了解最新的就业情况,得找现在的大四。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务