Codeforces Round #347 (Div. 1) B. International Olympiad

185 篇文章 0 订阅
116 篇文章 0 订阅

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.

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


分析:找规律。

#include <cstdio>
#include <stdlib.h>
#include <cstring>
#include <iostream>
using namespace std;
int n;
char a,b,c,d,s[11];
long long f[10] = {0,0,0,0,3099,13099,113099,1113099,11113099,111113099}; 
int main()
{
	cin.sync_with_stdio(false);
	cin>>n;
	for(int i = 1;i <= n;i++)
	{
		cin>>a>>b>>c>>d;
		cin>>s;
		int l = strlen(s);
		if(l <= 3)
		{
			if(l == 1) 
			{
				if(atoi(s) == 9) cout<<1989<<endl;
				else cout<<199<<s<<endl;
			}
			if(l == 2)
			{
				if(atoi(s) == 99) cout<<1999<<endl;
				else cout<<20<<s<<endl;
			}
			if(l == 3)
			{
				if(atoi(s) < 99) cout<<3<<s<<endl;
				else cout<<2<<s<<endl;
			}
		}
		else
		{
			if(atol(s) < f[l]) cout<<1<<s<<endl;
			else cout<<s<<endl;
		}
	} 
 } 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值