Source Code
#include<bits/stdc++.h>
////#include "cmake-build-debug/Car.h"
using namespace std;
#define endl         '\n'
#define ll           long long
const int N = 2e5 + 5 ;
void fast() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}
int main() {
    fast() ;
    int t ;
    cin>>t ;
    map<string , int >exist , mp  ;
    while (t -- )
    {
        string x ;
        cin >> x ;
        if (!exist[x])
        {
            cout  << "ok" << endl ;
            exist[x] ++ ;
        }
        else
        {
            int cnt = mp[x] ;
            if (cnt == 0 )cnt = 1  ;
            string temp = x ;
            temp += to_string(cnt) ;
            while (exist[temp])
            {
                cnt++;
                temp = x ;
                temp  += to_string(cnt) ;
            }
            cout << temp << endl ;
            exist[temp]++ ;
            mp[x] = cnt ;
        }
    }
    return  0 ;
}
Copy
Registration System Zidaan
GNU G++17
205 ms
10.3 MB
Accepted