International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition.
For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995.
You are given a list of abbreviations. For each of them determine the year it stands for.
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process.
Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits.
For each abbreviation given in the input, find the year of the corresponding Olympiad.
5 IAO'15 IAO'2015 IAO'1 IAO'9 IAO'0
2015 12015 1991 1989 1990
4 IAO'9 IAO'99 IAO'999 IAO'9999
1989 1999 2999 9999
题意:告诉你一个比赛是从1989年开始举办的,然后我们采用一种缩写形式。比如1989采用9,1990采用0.
然后就是已经使用过的不能再使用了,比如说1999就需要采用99了。
然后给你缩写,让你写出对应的年份。
这个题一直往下写就可以了,然后大约到第4位开始就有个规律,直接分类讨论就可以了。
#include <cstdio>
#include <queue>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const long long inf = 1e9;
const int MAXN = 1e5+7;
int n;
string get_ans(string num)
{
int l = num.size();
if(l == 1)
{
if(num == "9")return "1989";
else return "199"+num;
}
else if(l == 2)
{
if(num == "99")return "1999";
else return "20"+num;
}
else if(l == 3)
{
if(num == "099")return "2099";
else if(num[0] == '0')return "3"+num;
else return "2"+num;
}
else if(l == 4)
{
if(num>="3099")return num;
else return "1"+num;
}
else if(l == 5)
{
if(num>="13099")return num;
else return "1"+num;
}
else if(l == 6)
{
if(num>="113099")return num;
else return "1"+num;
}
else if(l == 7)
{
if(num>="1113099")return num;
else return "1"+num;
}
else if(l == 8)
{
if(num>="11113099")return num;
else return "1"+num;
}
else if(l == 9)
{
if(num>="111113099")return num;
else return "1"+num;
}
return "";
}
int main()
{
scanf("%d",&n);
string s;
for(int i = 0 ; i < n ; ++i)
{
cin>>s;
s = s.substr(4,s.size());
cout << get_ans(s) << endl;
}
return 0;
}