cf 4 c(string +map)

Registration system在這裏插入圖片描述

Input

4
abacaba
acaba
abacaba
acab

Output

OK
OK
abacaba1
OK

Input

6
first
first
second
second
third
third

Output

OK
first1
OK
second1
OK
third1

思路:

1.map+string以及
2. string裏的count函數

#include <iostream>
#include <cstring>
#include <map>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
const int maxn=1e5+10;
map<string,int>ma;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    string s;
    cin>>n;
    For(i,1,n)
    {
        cin>>s;
        if(ma.count(s))
            cout<<s<<ma[s]<<endl;
        else
            cout<<"OK"<<endl;
        ma[s]++;
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章