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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t; cin >> t;
    map<string, int>m;
    while (t--) {
        string s; cin >> s;
        int cnt = 0;
        if (!m.count(s)) {
            cout << "ok\n";
            m[s]++;
        }
        else {
            while (m.count(s + to_string(m[s]))) {
                m[s]++;
            }
            s = s + to_string(m[s]);
            cout << s << "\n";
            m[s]++;
        }
    }
	return 0;
}
Copy
Registration System Mohamedmaher
GNU G++17
173 ms
10.5 MB
Accepted