Source Code
#include<bits/stdc++.h>

using namespace std;

#define fast ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);

typedef long long ll;

const ll N = 200111, MOD = 1e9 + 7;

ll n;

string x;

map<string, pair<bool, ll> > mp;

int main()
{
    fast
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> x;
        if(mp[x].first)
        {
            ll idx = mp[x].second + 1;
            while(mp[x + to_string(idx)].first)
            {
                idx++;
            }
            cout << x << idx << endl;
            mp[x + to_string(idx)].first = 1;
            mp[x].second = idx - 1;
        }
        else
        {
            mp[x].first = 1;
            cout << "ok" << endl;
        }
    }
}
Copy
Registration System Mohamad_Abodan
GNU G++17
463 ms
11.3 MB
Accepted