codeforces Round #347 (Div. 2) C - International Olympiad

思路:从后往前一位一位的模拟,每次判断一下当前枚举的数是否之间枚举过了。或者当前枚举数过小,小于1989.

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cstdlib>
 4 #include<iostream>
 5 #include<queue>
 6 #include<stack>
 7 #include<cmath>
 8 #include<algorithm>
 9 #include<malloc.h>
10 using namespace std;
11 #define clc(a,b) memset(a,b,sizeof(a))
12 #define inf 0x3f3f3f3f
13 const int N=10010;
14 #define LL long long
15 const double eps = 1e-5;
16 const double pi = acos(-1);
17 // inline int r(){
18 //     int x=0,f=1;char ch=getchar();
19 //     while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
20 //     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
21 //     return x*f;
22 // }
23 
24 int vis[20];
25 int a[15]={1990,1991,1992,1993,1994,1995,1996,1997,1998,1989};//看成基数数组
26 int main(){
27     int T;
28     scanf("%d",&T);
29     char s[10];
30     while(T--){
31         scanf("%s",s);
32     int len = strlen(s);
33     int bas=s[len-1]-'0';
34     int extra=0;
35     int index=1;
36     int total=0;
37     int cur;
38     for(int i=len-1;s[i]>='0'&&s[i]<='9';i--){
39         extra+=(s[i]-'0')*index;
40         index*=10;
41         int pre=a[bas]/index-1;
42         bool flag=true;
43         while(flag){
44             pre++;
45             cur=pre*index+extra;
46             if(cur<a[bas]){
47                 continue;
48             }
49             flag=false;
50             for(int j=0;j<total;j++){
51                 if(vis[j]==cur){
52                     flag=true;
53                     break;
54                 }
55             }
56         }
57         vis[total++]=cur;
58     }
59     printf("%d\n",vis[--total]);
60     }
61     return 0;
62 }
View Code

 

posted @ 2016-04-20 21:42  yyblues  阅读(228)  评论(0编辑  收藏  举报