Source Code
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <stdio.h>
#define ll long long
#define mem(a,n) memset((a),n,sizeof (a))
void fast();
ll gcd(ll x, ll y) { return(!y ? x : gcd(y, x % y)); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
int dx[]{ 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[]{ 0, 0, 1, -1, 1, -1, 1, -1 };
using namespace std;

int main()
{
    //freopen("input.txt" ,"r" ,stdin);
   //freopen("output.txt" ,"w" ,stdout);
    fast();
    int t; cin >> t;
    map<string, int>mp;
    while (t--) {
        string s; cin >> s;
        if (mp[s] == 0) {
            cout << "ok\n";
            mp[s]++; int indx =  -1;
            for (int i = s.size() - 1; i >= 0; i--)
                if (s[i] >= '0' && s[i] <= '9')indx = i;
                else break;
            if (indx != -1) {
                string temp = s.substr(indx);
                indx = stoi(temp);
                mp[s] = indx;
            }
        }
        else {

            while(mp[ s+(char)(mp[s] + '0')]!=0)mp[s]++;
            cout << s << mp[s] << "\n";
            mp[s + (char)(mp[s] + '0')]++;

        }
    //    cout << endl;
    }
   
    return 0;
}
void fast() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
Copy
Registration System Nourhan Hanna
GNU G++17
3066 ms
192 KB
Time Limit Exceeded