C. International Olympiad

来源:互联网 发布:商建刚 知产 编辑:程序博客网 时间:2024/06/03 16:35

C. International Olympiad
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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'9IAO'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.

Input

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.

Output

For each abbreviation given in the input, find the year of the corresponding Olympiad.

Examples
input
5IAO'15IAO'2015IAO'1IAO'9IAO'0
output
201512015199119891990
input
4IAO'9IAO'99IAO'999IAO'9999
output
1989199929999999

题意:告诉你一个比赛是从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;}







原创粉丝点击