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;

}
全部评论

相关推荐

看到这个内容真是闹麻了。。。。。。现在有了AI以后很多人面试都会作弊吗?&nbsp;那对老老实实面试的人岂不是不公平....
程序员牛肉:公平那是对小孩子讲的童话故事,成年人的世界只有能不能接受失败的后果。 你要是能接受面试作弊被发现之后多家公司联合永久拉黑的后果,你就搞。
你找工作的时候用AI吗?
点赞 评论 收藏
分享
牛客84809583...:举报了
点赞 评论 收藏
分享
练习生懒羊羊:开飞机把这个公司创飞吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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