Source Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define fixed(n) cout << fixed << setprecision(n);
#define mod 1000000007
#define cin(v) for (auto&i:v) cin >> i;
#define cout(v) for (auto&i:v) cout << i << " ";
#define ceil(n,m) (n / m + (n%m != 0))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void lil_codi_vert(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    #endif
}

//int dx[] = {1, 1, 1, 0, 0, -1, -1, -1};
//int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};


int main(){
    lil_codi_vert();
     set<string> data;
    // ll i = 1;
    // while(data.size() < 1e5){
    //     string chk = to_string(i);
    //     if(count(all(chk),'0') != 0) continue;
    //     data.emplace(to_string(i));
    //     i++;
    // }



    ll t; cin >> t;
    set<string> st;
    map<string, ll> ma;
    while(t--){
        string s;
        cin >> s;
        int cnt = 0;
        if(!st.count(s)){
            cout << "ok\n";
            st.insert(s);
            ma[s] = 1;
        }else{
            //cout << s << " " << ma[s] << "\n";
            while(st.count(s + to_string(ma[s]))){
                ma[s]++;
            }
            string k = s + to_string(ma[s]);
            st.insert(k);
            cout << k << "\n";
            ma[k] = 1;
        }
    }
    return 0;
}
Copy
Registration System aboelsoudJr
GNU G++17
257 ms
17.6 MB
Accepted