codeforces round#347 div2 C International Olympiad 想法题

 题目描述:给出一个从1989年开始的年份,每个年份用末尾的最少的数字来代表,如用9来代表1989,0来代表1990,
                ...用99来代表1999而不是用9来代表1999,因为9已经用在代表1989的时候了。现在对于一个不超过九位数的

                年份,输出其代表数。

思路:如图,观察发现,所有一位数能代表的年份是连续的,所有两位数能代表的年份是连续的,......,所有九位数能代表的年份是连续的,看图明白做法。

/*
    题目描述:给出一个从1989年开始的年份,每个年份用末尾的最少的数字来代表,如用9来代表1989,0来代表1990,
                ...用99来代表1999而不是用9来代表1999,因为9已经用在代表1989的时候了。现在对于一个不超过九位数的
                年份,输出其代表数。
*/
#pragma warning(disable:4786)
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<sstream>
#define LL long long
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define lson l,m,x<<1
#define rson m+1,r,x<<1|1
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
const double eps=1e-6;
char s[35] ;
int main()
{
    int n ;
    scanf("%d",&n);
    while(n--){
        char ch ;
        while(scanf("%c",&ch) == 1 && ch != 39 ) ;
        scanf("%s",s);
        int len = strlen(s) ;
        if(len < 4 ){
            if(len == 1){
                if(s[0] == '9')     printf("1989\n") ;
                else printf("199%c\n",s[0]) ;
            }
            else if(len == 2){
                if(strcmp("99",s) == 0)     printf("1999\n") ;
                else if(strcmp("00" , s) == 0)      printf("2000\n");
                else printf("20%s\n",s) ;
            }
            else{
                if(strcmp(s ,"098") <= 0)   printf("3%s\n" , s ) ;
                else    printf("2%s\n", s ) ;
            }
        }
        else{
            if(len == 4){
                if(strcmp(s , "3098") <= 0 )    printf("1%s\n",s);
                else    printf("%s\n" , s ) ;
            }
            else if(len == 5){
                if(strcmp(s , "13098") <= 0 )    printf("1%s\n",s);
                else    printf("%s\n" , s ) ;
            }
            else if(len == 6){
                if(strcmp(s , "113098") <= 0 )    printf("1%s\n",s);
                else    printf("%s\n" , s ) ;
            }
            else if(len == 7){
                if(strcmp(s , "1113098") <= 0 )    printf("1%s\n",s);
                else    printf("%s\n" , s ) ;
            }
            else if(len == 8){
                if(strcmp(s , "11113098") <= 0 )    printf("1%s\n",s);
                else    printf("%s\n" , s ) ;
            }
            else if(len == 9){
                if(strcmp(s , "111113098") <= 0 )    printf("1%s\n",s);
                else    printf("%s\n" , s ) ;
            }
        }
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值