题解 | #简单错误记录#
简单错误记录
http://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
#include<iostream>
#include<string>
#include<map>
#include<queue>
using namespace std;
int main()
{
string str;
int cows;
map<string,int> count;
queue<string> ans;
int size=0;
while(cin>>str>>cows)
{
//rfind找到'\'返回下标,找不到返回-1
int len=str.length()-str.rfind("\\")-1;
string houzui;
//如果后缀名部分超过16位则保留16位
if(len<16)
{
houzui=str.substr(str.rfind("\\")+1,len) ;
}
else
{
houzui=str.substr(str.length()-16,16) ;
}
//加上对应的行号
string temp=houzui+" "+to_string(cows);
if(size<8)
{
if(count.find(temp)==count.end())//只记录第一次出现的字符串
{
ans.push(temp);
size++;
}
}
else //当有8条记录,只保留最后8条
{
if(count.find(temp)==count.end())//只记录第一次出现的字符串
{
ans.pop();
ans.push(temp);
}
}
count[temp]++;
}
int n =ans.size();
while(n--)
{
string temp=ans.front();//取出字符串,加上出现次数输出
cout<<temp<<" "<<count[temp]<<endl;
ans.pop();
}
return 0;
}
SHEIN希音公司福利 261人发布