0w1

CFR 664 C. International Olympiad ( Adhoc )

Problem - C - Codeforces
Many people were hacked for this problem, for cases where leading zeros exist.
Simply find answer for each suffix from smaller length, and it will do fine.
P.S. This round was unrated QQ.

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 3;
typedef long long ll;

int n;

int main(){
    cin >> n;
    while( n-- ){
        string s; cin >> s;
        s = s.substr( 4 );
        set< int > st;
        ll ans;
        for( int i = s.size() - 1; i >= 0; --i ){
            ll v = stoi( s.substr( i ).c_str() );
            ll t = 1;
            for( int j = 0; j < s.size() - i; ++j )
                t *= 10;
            while( v < 1989 || st.count( v ) )
                v += t;
            st.insert( v );
            if( i == 0 ) ans = v;
        }
        cout << ans << endl;
    }
    return 0;
}