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
这道题wa了很多次,后来找到规律后才过了, 长度为n的数字字符串的总个数为10^(n-1)个,
通过这个规律算出当前数字字符串对应的年数是从1989开始的第几年,之后加上1989就可以了。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#define Si(a) scanf("%d",&a)
#define Sl(a) scanf("%lld",&a)
#define Sd(a) scanf("%lf",&a)
#define Ss(a) scanf("%s",a)
#define Pi(a) printf("%d\n",(a))
#define Pl(a) printf("%lld\n",(a))
#define Pd(a) printf("%lf\n",(a))
#define Ps(a) printf("%s\n",(a))
#define W(a) while(a--)
#define mem(a,b) memset(a,(b),sizeof(a))
#define FOP freopen("data.txt","r",stdin)
#define inf 0x3f3f3f3f
#define maxn 1000010
#define mod 1000000007
#define PI acos(-1.0)
#define LL long long
using namespace std;

LL dp[20];

LL get_m(int n)
{
    LL ans=1;
    while(n--)ans*=10;
    return ans;
}

LL get_num(int n)
{
    if(n==1)return 9;
    else if(n==2||n==3)return 99;
    else if(n==4)return 3099;
    else if(n>4)
    {
        n-=5;
        LL num=10000;
        LL ans=num;
        while(n--)
        {
            ans+=num*10;
            num*=10;
        }
        return ans+3099;
    }
}

int main()
{
    int i;
    mem(dp,0);
    for(i=2;i<10;i++)
    {
        dp[i]=dp[i-1]+get_m(i-1);
    }
    //FOP;
    int T;
    Si(T);
    while(T--)
    {
        char a[30];
        LL ans=0;
        Ss(a);
        int len=strlen(a)-4;
        LL n=0;
        for(i=4;a[i]!='\0';i++)
        {
            n=n*10+a[i]-'0';
        }
        LL numl=get_num(len);
        if(n>=numl)
        {
            ans=1989+dp[len]+(n-numl);
        }
        else
        {
            ans=1989+dp[len]+(get_m(len)+n-numl);
        }
        Pl(ans);
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,Codeforces Round 511 (Div. 1)是一个比赛的名称。然而,引用内容中没有提供与这个比赛相关的具体信息或问题。因此,我无法回答关于Codeforces Round 511 (Div. 1)的问题。如果您有关于这个比赛的具体问题,请提供更多的信息,我将尽力回答。 #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Codeforces Round 867 (Div. 3)(A题到E题)](https://blog.csdn.net/wdgkd/article/details/130370975)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值