题解 | #简单错误记录#

简单错误记录

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

#include <iostream>
#include <cstring>
#include<sstream>
#include <string>
#include <system_error>
#include<vector>
#include<cmath>
using namespace std;

struct ErrorRecord
{
    public:
    string fileName;
    int errorCode;
    int quantity = 0;
};
bool find(vector<ErrorRecord>&errorRecords,int code,string name)
{
    for( decltype(errorRecords.size())i = 0;i < errorRecords.size();i++)
    {
        if(errorRecords[i].errorCode == code&& name == errorRecords[i].fileName)
            {
                errorRecords[i].quantity++;
                return true;
            }
    }
    return false;
}
int main() {
    string str;
    vector<string> inputs;//记录每行输入
    vector<ErrorRecord> errorRecords;//整理好的输入
    int len = 0;//记录输入
    while(getline(cin,str))
    {
        len++;
        inputs.push_back(str);
    }
    for(int i = 0;i < len; i++)
    {
        string temp;
        stringstream ss;
        ss << inputs[i];
        vector<string> record;
        while(getline(ss,temp,' '))
        {
            record.push_back(temp);
        }
        stringstream path;
        path<<record[0];
        string pathstr;
        while(getline(path, pathstr,'\\')){}
        if(pathstr.size()>16)
        {
            string tempstr(pathstr,(pathstr.size()-16));
            pathstr = tempstr;
        }
        int code=0;
        for(int j = 0,dijit = record[1].size()-1;j<record[1].size();j++)
        {
            code += (record[1][j]-48)*pow(10,dijit);
            dijit--;
        }
        if(!find(errorRecords,code,pathstr))
        {
            ErrorRecord errorRecord;
            errorRecord.fileName = pathstr;
            errorRecord.errorCode = code;
            errorRecord.quantity = 1;
            errorRecords.push_back(errorRecord);
        }
    }
    if(errorRecords.size()<=8)
    {
        for(auto i:errorRecords)
            cout<<i.fileName<<" "<<i.errorCode<<" "<<i.quantity<<endl;
    }
    else 
    {
        for(int i = errorRecords.size()-8;i<errorRecords.size();i++)
        {
            cout<<errorRecords[i].fileName<<" "<<errorRecords[i].errorCode<<" "<<errorRecords[i].quantity<<endl;
        }
            
    }
    

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

今年读完研的我无房无车无对象,月入还没有过万&nbsp;看到他在朋友圈晒房产证,感叹自己白读了这么多年书
梦想是成为七海千秋:那咋了,双9毕业的现在还没存款呢(因为没念完),高中毕业的去直播带货月入几百万也是完全有可能的,退一万步讲,有些人刚出生父母就给买车买房了,上哪说理去,哪怕是同一个起点也会有截然不同的走向,过好自己的生活就完事了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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