链接:
https://codeforces.com/problemset/problem/4/C
题意:
给定n个字符串,第一次出现的直接输出,第n次出现的后面加上n-1;
输入
4
abacaba
acaba
abacaba
acab
输出量
OK
OK
abacaba1
OK
输入
6
first
first
second
second
third
third
输出量
OK
first1
OK
second1
OK
third1
解:
time卡5s,第一次用的muliset,超时了,换成了map来映射解决问题
实际代码:
#include<iostream>
#include<map>
#include<cstring>
#include<string>
using namespace std;
typedef long long int ll;
map<string,int>ans;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
string temp;
cin>>temp;
ans[temp]++;
if(ans[temp]>1)
{
cout<<temp<<ans[temp]-1<<endl;
}
else
{
cout<<"OK"<<endl;
}
}
}
限制:
time limit per test
5 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output