Codeforces 664C:International Olympiad

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 formIAO'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 andIAO'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
5
IAO'15
IAO'2015
IAO'1
IAO'9
IAO'0
output
2015
12015
1991
1989
1990
input
4
IAO'9
IAO'99
IAO'999
IAO'9999
output
1989
1999
2999
9999

题意是给出了一个数字的后缀,要求最终这个数字大于等于1989,并且在最小的情况下,这个数字之前没有被占用过。求最终拼凑的数字。

提议最初理解错了。。。当然这个题意个人觉得还是挺绕的。。。

数字最长就是9个字符,找一下规律。

1个字符在[1989-1998]

2个字符在[1999-2098]

3个字符在[2099-3098]

4个字符在[3099-13098]

5个字符在[13099-113098]

6个字符在[113099-1113098]

7个字符在[1113099-11113098]

8个字符在[11113099-111113098]

9个字符在[111113099-1111113098]

代码:

#pragma warning(disable:4996)
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

#define INF 0x333f3f3f
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))

const ll mod = 1e9 + 7;
const int maxn = 3e2 + 5;
const double PI = acos(-1.0);

int n;
string x;

void solve()
{
	sa(n);
	repp(i, 1, n)
	{
		cin >> x;
		x = x.substr(4);
		if (x.length() == 1)
		{
			if (x[0] >= '0'&&x[0] <= '8')
			{
				cout << "199" + x << endl;
			}
			else
			{
				cout << "1989" << endl;
			}
		}
		else if (x.length() == 2)
		{	
			if (x == "99")
			{
				cout << "1999" << endl;
			}
			else
			{
				cout << "20" + x << endl;
			}
		}
		else if (x.length() == 3)
		{
			if (x >= "000"&&x <= "098")
			{
				cout << "3" + x << endl;
			}
			else
			{
				cout << "2" + x << endl;
			}
		}
		else if (x.length() == 4)
		{
			if (x >= "3099"&&x <= "9999")
			{
				cout << x << endl;
			}
			else
			{
				cout << "1" + x << endl;
			}
		}
		else if (x.length() == 5)
		{
			if (x >= "13099"&&x <= "99999")
			{
				cout << x << endl;
			}
			else
			{
				cout << "1" + x << endl;
			}
		}
		else if (x.length() == 6)
		{
			if (x >= "113099"&&x <= "999999")
			{
				cout << x << endl;
			}
			else
			{
				cout << "1" + x << endl;
			}
		}
		else if (x.length() == 7)
		{
			if (x >= "1113099"&&x <= "9999999")
			{
				cout << x << endl;
			}
			else
			{
				cout << "1" + x << endl;
			}
		}
		else if (x.length() == 8)
		{
			if (x >= "11113099"&&x <= "99999999")
			{
				cout << x << endl;
			}
			else
			{
				cout << "1" + x << endl;
			}
		}
		else if (x.length() == 9)
		{
			if (x >= "111113099"&&x <= "999999999")
			{
				cout << x << endl;
			}
			else
			{
				cout << "1" + x << endl;
			}
		}
	}
}

int main()
{
#ifndef ONLINE_JUDGE  
	freopen("i.txt", "r", stdin);
	freopen("o.txt", "w", stdout);
#endif
	solve();
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值