Source Code
//Esraa_Taha
//إن مررت من هنا فأدع لي
#include <bits/stdc++.h>
using namespace std;
#define zrebeooo           ios_base::sync_with_stdio(false);cin.tie(NULL);
#define zrebeooo2          cin.tie(0); cin.sync_with_stdio(0);
#define ll                 long long
#define sz(x)              (int)x.size()
#define pb                 push_back
#define pf                 push_front
#define po                 pop_back
#define pi                 acos(-1)          //radian
#define eu(s)              s.erase(unique(be(s)),s.end())
#define fs(n)              fixed<<setprecision(n)
#define vi                 vector<int>
#define vl                 vector<ll>
#define el                 '\n'
#define S                  second
#define F                  first
#define be(s)              (s).begin() , (s).end()
#define clr(x , v)         memset(x , v , sizeof(x))
#define sz2(a)             sizeof((a))/sizeof((a[0]))
#define ln(i,k,n)          for (int i=n ; i>=k ; i--)
#define l(i,k,n)           for (int i=k ; i<n ; i++)
#define loop(it , s)       for (it= s.begin() ; it != s.end() ; it++)
#define loopr(it , s)      for (it= s.rbegin() ; it != s.rend() ; it++)
#define M                  1000000007
#define test               int t; cin>>t; while(t--)

//======================================================
ll gcd(ll a, ll b) //O(log(min(a,b)))
{
    return (b ? gcd (b, a%b) : a);
}
ll lcm(ll a, ll b)
{
    return (a / gcd(a, b))*b;
}
ll egcd(ll a, ll b, ll& x,ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = egcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}
//=======================================================
void input()
{
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
#endif
}
//======================================================
/*int dx[] = { -1, 0, 0, 1, -1, -1, 1, 1}; //j
int dy[] = { 0, 1, -1, 0, -1, 1, 1, -1}; //i*/
//======================================================
ll mulmod(ll a , ll b , ll mod) {
    if(a>b) return mulmod(b,a,mod);
    ll x = 0, y = a % mod;
    while (b) {
        if (b&1) {
            x = (x%mod + y%mod)%mod;
        }
        y = (y <<= 1)%mod;
        b >>= 1;
    }
    return x%mod;
}
//======================================================
ll power(ll b , ll p , ll m){
    ll an=1;
    while(p){
        if(p&1){
            an*=b;
            an%=m;
        }
        b*=b;
        b%=m;
        p >>= 1;
    }
    return an%m;
}
//======================================================
/*vector<bool> is_prime;
vl s;
void sieve(ll n) {
	is_prime.assign(n+1, true);
	is_prime[0] = is_prime[1] = 0;
	for(ll i=4 ; i<=n ; i+=2) is_prime[i]=0;

	for (ll i = 3 ; i*i <= n ; i+=2){
		if (is_prime[i])
			for (ll j = i * i; j <= n; j += i) is_prime[j] = 0;
	}
	l(i , 2 , n+1) if(is_prime[i]) s.pb(i);
}*/
//======================================================
void linearsieve(int n){
    vi pr;
    vector<bool> lp(n+1 , 0);
for (int i=2; i <= n; ++i) {
    if (lp[i] == 0) {
        pr.push_back(i);
    }
    for (int j=0; j < (int)pr.size() && pr[j] <= lp[i] && i*pr[j] <= n; ++j) {
        lp[i * pr[j]] = 1;
    }
}
}
//======================================================
vector<ll> primedivs(ll N){
    vector<ll> primeDivs[N];
    for (ll i = 2; i <= N; i++) {
	   if(sz(primeDivs[i])) continue;

       for (ll j = i; j <= N; j += i)
	      primeDivs[j].pb(i);
  }
  return primeDivs[N];
}
//======================================================
int sto(string h){
      int y=0;
      l(i , 0 , sz(h)) y*=10 , y+=(h[i]-'0');
      return y;
}
int main ()
{
    zrebeooo    zrebeooo2
    //input();
                             //مهما الدنيا إتنيلت ضلمت لازم يبقى عندك زفت أمل و تعرف إن في نور في أخر أم النفق//
                                              //THINK TWICE .. CODE ONCE//
                                                       //ACPC//
                                                     //فاكس؟ فاكس//
                           int n;
                           cin>>n;
                           map<string,int> g;
                           map<string,map<int,int>> m;

                           while(n--){
                                 string h; cin>>h;
                                 if(g[h]==0){
                                      cout<<"ok\n";
                                      g[h]=1;
                                      int y=sz(h)-1;
                                      while(y>=0 && isdigit(h[y])){
                                            if(g[h.substr(0,y)]){
                                                  m[h.substr(0,y)][sto(h.substr(y))]++;
                                                  break;
                                            }
                                            y--;
                                      }
                                 }
                                 else{
                                       while(m[h][g[h]]) g[h]++;
                                       string s = h;
                                       s += to_string(g[h]);
                                       cout<<s<<el;
                                       g[s]=1; m[h][g[h]]++;
                                 }
                           }
                   return 0;
                }
Copy
Registration System Gargera
GNU G++17
241 ms
14.9 MB
Wrong Answer