题解 | 简单错误记录

简单错误记录

https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb?tpId=37&tags=&title=&difficulty=0&judgeStatus=0&rp=1&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37

#include <iostream>
#include<unordered_map>
#include<string>
#include<deque>
using namespace std;

int main() {
    string s;
    unordered_map<string, int>mp;
    deque<string>dq;
    while (getline(cin, s)) {
        int pos, end = 0;
        string str = s.substr(s.find_last_of('\\') + 1);
        pos = str.find_last_of(' ');
        if (pos > 16) {
            str = str.substr(pos - 16);
        }
        if (mp.find(str) == mp.end())dq.push_back(str);
        ++mp[str];//if语句后不加花括号{}时,仅会执行紧随其后的第一条语句。
        //如果`str`不在map中:1. mp[str]会插入`str`,并将其值初始化为`0`;2. 然后`++`操作将该值增加为`1`。
        //如果`str`已经在map中:直接将其值加1。
        if (dq.size() > 8)dq.pop_front();
    }
    for (auto i : dq) {
        cout << i << " " << mp[i] << endl;
    }
}
// 64 位输出请用 printf("%lld")

#第一份工作能做外包吗?#
全部评论

相关推荐

点赞 评论 收藏
分享
11-04 19:05
已编辑
东莞城市学院 单片机
不知道怎么取名字_:你这个要实习两年?哪有这么久的,感觉就是即使你毕业了,但还按实习的话,是不是不用给你缴社保公积金啥的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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