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

using namespace std;
typedef long long ll;
#define x           first
#define y           second
#define all(v)      v.begin(),v.end()
#define clr(v,d)    memset(v,d,sizeof(v));

const int N = 1e5 + 10;

const ll mod = 1e9 + 7;

int n , a[N];


int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);

    cin >> n;

    map<string , int> fr , en ;

    while(n--)
    {
        string s ;
        cin >> s;
        if(!fr[s])
        {
            cout << "ok\n";
            fr[s]++;
            en[s] = 1;
        }
        else
        {
            string ss = s + to_string(en[s]);
            int j = en[s]+1 ;
            while(fr[ss]) ss = s + to_string(j) , j++;
            fr[ss] = 1;
            en[s] = j ;
            en[ss] = max(en[ss] , 1);
            cout << ss << "\n" ;
        }
    }

    return 0;
}
Copy
Registration System MuhammadHassan
GNU G++17
303 ms
17.6 MB
Accepted