CodeForces 662 D.International Olympiad(构造)

Description

给出一个数字的后缀,要求添加一些前缀使得该数字不小于1989且使得这个数字在之前没有被用过的情况下尽可能小

Input

第一行一个整数 T T 表示用例组数,每组用例输入一个 IAO +一个数字后缀,保证数字后缀长度不超过9位 (1T1000) ( 1 ≤ T ≤ 1000 )

Output

输出添加合法前缀后的数字

Sample Input

5
IAO’15
IAO’2015
IAO’1
IAO’9
IAO’0

Sample Output

2015
12015
1991
1989
1990

Solution

分别考虑后缀长度为1~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

然后根据不同的后缀输出对应的前缀即可

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
string s,c[10];
//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 
int main()
{
    c[4]="3099",c[5]="13099",c[6]="113099",c[7]="1113099",c[8]="11113099",c[9]="111113099";
    int T;
    cin>>T;
    while(T--)
    {
        cin>>s;
        s=s.substr(4);
        int n=s.length();
        if(n==1)
        {
            if(s=="9")cout<<"1989"<<endl;
            else cout<<"199"<<s<<endl;
        } 
        else if(n==2)
        {
            if(s=="99")cout<<"1999"<<endl;
            else cout<<"20"<<s<<endl;
        }
        else if(n==3)
        {
            if(s<="098")cout<<"3"<<s<<endl;
            else cout<<"2"<<s<<endl;
        }
        else 
        {
            if(s>=c[n])cout<<s<<endl;
            else cout<<"1"<<s<<endl;
        }
    } 
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值