题解 | #简单错误记录#

简单错误记录

https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb

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

map<pair<string, string>, int> elog;
vector<pair<string, string>> log_out;   // 按顺序记录出现的错误

void RecordError(pair<string, string> key) {
    if(elog.count(key)) {    // 错误记录已存在
        elog[key]++;
    }
    else {
        elog[key] = 1;
        log_out.push_back(key);
    }
}

int main() {
    string input;
    while(getline(cin, input)) {
        pair<string, string> err_key;   // <文件名,行数>
        int fname_begin = input.find_last_of('\\') + 1;
        int fname_end = input.find_first_of(' ');
        if(fname_end - fname_begin > 16)
            err_key.first = input.substr(fname_end - 16, 16);
        else 
            err_key.first = input.substr(fname_begin, fname_end - fname_begin);
        err_key.second = input.substr(fname_end + 1);

        RecordError(err_key);
    }
    int start_pos = log_out.size() > 8 ? log_out.size()-8 : 0;

    for(int i=start_pos; i<log_out.size(); ++i) {
        cout << log_out[i].first << ' ' << log_out[i].second << ' ' << elog[log_out[i]] << endl;
    }

    return 0;
}
// 64 位输出请用 printf("%lld")
全部评论

相关推荐

07-09 15:55
门头沟学院 Java
点赞 评论 收藏
分享
07-11 10:56
门头沟学院 Java
码客明:大胆的说自己能实习6个月就行
点赞 评论 收藏
分享
仁者伍敌:牛子这些人还会点一个自动回复,boss都不带回复的
点赞 评论 收藏
分享
07-07 17:06
已编辑
深圳技术大学 golang
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 12:05
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务