题解 | #简单错误记录#
简单错误记录
https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb
//字符串操作和使用map构建哈希表
#include <bits/stdc++.h>
#include <string>
#include <vector>
using namespace std;
int main() {
string str;
vector<string> s1;
int a,b,fa=0;
map<string,int> m1;
while(getline(cin,str))
{
string s2;
a=str.find(' ');
b=str.find_last_of('\\');//\转义字符
s2=str.substr(b+1,a-b-1);
//cout<<s2<<'0'<<endl;
if(s2.size()>16)
{
s2=s2.substr(s2.size()-16)+str.substr(a);
//cout<<s2<<' '<<s2.size()<<endl;
}
else {
s2=s2+str.substr(a);
}
if(find(s1.begin(),s1.end(),s2)==s1.end())
{
m1[s2]=1;
s1.push_back(s2);
if(s1.size()>8)
{
fa+=1;
}
}
else
{
m1[s2]+=1;
}
}
for(vector<string>::iterator it=s1.begin()+fa;it!=s1.end();it++)
{
cout<<*it<<' '<<m1[*it]<<endl;
}
}
// 64 位输出请用 printf("%lld")

