Source Code
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include<math.h>
#include <string.h>
using namespace std;
typedef vector<int> vi ;
typedef long long ll;
#define all(x) (x).begin() , (x).end()
#define allR(x) (x).rbegin() , (x).rend()
#define pb push_back
const int N = 3e5+5, MX=1e9;
int a[N];
map<string,int> freq, mp;
int main(){ 
    // freopen("input.txt", "r", stdin);
    int n, mn=-1;
    cin >> n;
    while ( n-- ){
        string s;
        cin >> s;
        if ( !freq[s] ){
            puts("ok");
            mp[s]++;
            freq[s]++;
        }
        else{
            while ( freq[s+to_string(mp[s])] )
                mp[s]++;
            string curr = s+to_string(mp[s]);
            mp[curr]++;
            freq[curr]++;
            cout << curr <<"\n";

        }
    }
}
Copy
Registration System Rand()
GNU G++17
721 ms
17.7 MB
Accepted