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

时间:2023-03-08 16:22:22
codeforces  Round #347 (Div. 2)  C - International Olympiad

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

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=;
#define LL long long
const double eps = 1e-;
const double pi = acos(-);
// inline int r(){
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
// return x*f;
// } int vis[];
int a[]={,,,,,,,,,};//看成基数数组
int main(){
int T;
scanf("%d",&T);
char s[];
while(T--){
scanf("%s",s);
int len = strlen(s);
int bas=s[len-]-'';
int extra=;
int index=;
int total=;
int cur;
for(int i=len-;s[i]>=''&&s[i]<='';i--){
extra+=(s[i]-'')*index;
index*=;
int pre=a[bas]/index-;
bool flag=true;
while(flag){
pre++;
cur=pre*index+extra;
if(cur<a[bas]){
continue;
}
flag=false;
for(int j=;j<total;j++){
if(vis[j]==cur){
flag=true;
break;
}
}
}
vis[total++]=cur;
}
printf("%d\n",vis[--total]);
}
return ;
}