C++题解 | #简单错误记录 20行代码#

简单错误记录

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

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main (){
    vector<string> log;
    vector<int> num(101);
    int i = 0;
    string str;
    while(getline(cin, str)){
        string log1;
        int n1 = str.find_last_of('\\'), n2 = str.find_first_of(' ');
        log1 = (n2 - n1) > 16 ? str.substr(n2-16) : str.substr(n1+1);
        vector<string>::iterator it = find(log.begin(), log.end(), log1);
        if(it == log.end()){
            log.push_back(log1);
            num[i++] = 1;
        }
        else
            num[distance(log.begin(), it)]++;
    }
    for(int i = log.size() > 8 ? log.size() - 8 : 0; i < log.size(); ++i){
        cout << log[i] << ' ' << num[i] << endl;
    }
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务