首页 > 其他 > 详细

简单错误记录

时间:2016-12-29 07:28:37      阅读:131      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include<string>
#include<list>
using namespace std;

struct record{
    string name;
    int line;
    int count;
};

string getname(string str)
{
    int sz = str.length();
    int i;
    for(i=sz-1;  i>=0 && str[i]!=\\; i-- );

    if(sz-1-i>16)
        return str.substr(sz-16);
    else
        return str.substr(i+1);
}

int main()
{
    list<record> listrd;
    string str;
    int num;
    while(cin>>str>>num)
    {
        string name = getname(str);
        int line = num;
        record rd;

        bool exist = false;
        for(list<record>::iterator itr=listrd.begin(); itr!=listrd.end(); itr++)
        {
            if((*itr).name == name && (*itr).line == line)
            {
                exist = true;
                (*itr).count++;
            }
        }
        if(exist==false)
        {
            if(listrd.size()==8)
            {
                listrd.pop_front();
            }
            rd.name = name;
            rd.line = line;
            rd.count = 1;
            listrd.push_back(rd);
        }
    }

    for(list<record>::iterator itr=listrd.begin(); itr!=listrd.end(); itr++)
    {
        cout<<(*itr).name<< <<(*itr).line<< <<(*itr).count<<endl;
    }

    return 0;
}

 

简单错误记录

原文:http://www.cnblogs.com/hardsoftware/p/6231029.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!