Source Code
//Includes
#include <bits/stdc++.h>
#include <cstdio> //For input/ouput file
#include <numeric> //For GCD and LCM
#include <iomanip> //For Decimal Points
#include <chrono>

//Marcos
#define fast_io() std::ios::sync_with_stdio(false); std::cin.tie(NULL);
#define TestCases(type) type t; std::cin >> t; while(t--)
#define ArrOne(name, type, size) type* name = new type[size]
#define ArrTwo(name, type, rows, cols) type** name = new type*[rows]; for(int i = 0; i < rows; i++){ name[i] = new type[cols]; }
#define sp(a, b, type) { type temp = a; a = b; b = temp; }
#define PI 3.14159265358979
#define MOD 1000000007
#define ll long long
#define lli long long int
#define ull unsigned long long
#define ld long double
#define li long int


void solve() {
    int n; std::cin >> n;
    std::unordered_map<std::string, int> mp;
    std::string name = "";
    while(n--) {
        std::cin >> name;
        if(mp.find(name) == mp.end()) {
            mp.insert(std::make_pair(name, 0));
            std::cout << "ok\n";
        } else {
            int tmp = ++mp[name];
            char ch = (tmp + '0');
            name.push_back(ch);
            while(mp.find(name) != mp.end()) {
                name.erase(name.end() - 1);
                tmp = ++mp[name];
                ch = (tmp + '0');
                name.push_back(ch);
            }
            mp.insert(std::make_pair(name, 0));
            std::cout << name << "\n";
        }
    }
}

void testCases() {
    TestCases(int)
        solve();
}

//main function
int main()
{
    //#
    fast_io();
    //#

    //#
    #ifndef ONLINE_JUDGE
        std::freopen("input.txt", "r", stdin);
        std::freopen("output.txt", "w", stdout);
    #endif
    //#

    //testCases();
    solve();

    return 0;
}
Copy
Registration System talalomar001
GNU G++17
3065 ms
316 KB
Time Limit Exceeded