Source Code
//#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
  
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
  
void Fast()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void File() {
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}
typedef long long ll;
void justify(int n,int x)
{
    string s=to_string(n);
    for(int i=0;i<x-s.size();i++)cout<<' ';
    cout<<s;
}
string to_s(string x,int n)
{
    string s;
    while(n)
    {
        s+=n%10+'0';
        n/=10;
    }
    reverse(s.begin(),s.end());
    return x+s;
}
void solve()
{
    int n;
    cin>>n;
    map<string,int>mp;
    set<string>st;
    string s;
    string x;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        if(st.find(s)==st.end())
        {
            cout<<"ok\n";
            st.insert(s);
            mp[s]=1;
        }
        else
        {
            x=to_s(s,mp[s]);
            while(st.find(x)!=st.end())
            {
                mp[s]++;
                x=to_s(s,mp[s]);
            }
            mp[x]=1;
            st.insert(x);
            cout<<x<<'\n';
        }
    }
}
int main()
{
    File();
    Fast();
    
    int t=1;
    //cin>>t;
    for (int i = 1; i <= t;i++ )
    {
        //cout<<"Case "<<i<<": ";
        solve();
    }

}
Copy
Registration System Ahmed_Aladdin
GNU G++17
277 ms
17.6 MB
Accepted