题解 | #简单错误记录# 哈希表加队列

简单错误记录

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

哈希表加队列

#include <algorithm>
#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
using namespace std;
int main() {
    string addr;
    int line;
    unordered_map<string,int> mp;
    queue<string> qstr;
    while(cin>>addr>>line){
        string temp,temp1;
        for(int i=addr.length()-1;i>=0;i--){
            if(addr[i]=='\\'){
                temp=addr.substr(i+1,addr.length()-i-1);
                if(temp.length()>16) temp=temp.substr(temp.length()-16,16);
                break;
            }
        }
        string key=temp+' '+to_string(line);
        if(mp.find(key)!=mp.end()){
            mp[key]+=1;
        }
        else{
            mp[key]=1;
            qstr.push(key);
            if(qstr.size()>8) qstr.pop();
        }
    }
    while(!qstr.empty()){
        string temp;
        temp=qstr.front();
        qstr.pop();
        cout<<temp<<' '<<mp[temp]<<endl;
    }
}
// 64 位输出请用 printf("%lld")

#C++#
全部评论

相关推荐

美丽的95后准备进厂:第二个是外卖➕点评吧,很眼熟
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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