题解 | #简单错误记录#

简单错误记录

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

#include <iostream>
#include<map>
#include<algorithm>
#include<sstream>
#include<queue>
using namespace std;
//关键是istringStream,很方便地进行字符串分割
string get_file_name(string s){
    istringstream tokenStream(s);
    string token;
    while(getline(tokenStream,token,'\\')){}
    int len=token.length();
    return token.substr(max(0,len-16),min(len,16));
}

int main() {
    map<string,int> m;
    queue<string> q;
    string s;
    while(getline(cin,s)){
        istringstream tokenStream(s);
        string token;
        getline(tokenStream,token,' ');
        string file_name=get_file_name(token);
        getline(tokenStream,token,' ');
        string file_line=file_name+' '+token;
        if(m.count(file_line)==0){
            q.push(file_line);
            while(q.size()>8){
                q.pop();
            }
            m[file_line]=1;
        }else{
            int v=m[file_line]+1;
            m[file_line]=v;
        }
    }
    while(!q.empty()){
        cout<<q.front()<<' '<<m[q.front()]<<endl;
        q.pop();
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

门口唉提是地铁杀:之前b站被一个游戏demo深深的吸引了。看up主页发现是个初创公司,而且还在招人,也是一天60。二面的时候要我做一个登录验证和传输文件两个微服务,做完要我推到github仓库,还要我加上jaeger和一堆运维工具做性能测试并且面试的时候投屏演示。我傻乎乎的做完以后人家跟我说一句现在暂时不招人,1分钱没拿到全是白干
你的秋招第一场笔试是哪家
点赞 评论 收藏
分享
zzzzhz:兄弟你先猛猛投简历至少三百家,能约到面试就去面。最近可以速成智能小车,智慧家居烂大街的项目,不需要自己写,只需要把里面的代码讲解看明白就行。把其中涉及到的八股文都拿出来单独背一下,我去年找工作就一个智能小车智慧家居找了10k差不多。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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