aixintao @ 2022-11-06 22:21:05
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int a[200];
int n;
void highplusecho(){ //高精加(正+反)
int b[200];
for (int i = 1;i<=a[0];i++){
b[i]=a[a[0]-i+1]; //转存反数
}
for (int i = 1;i<=a[0];i++){
a[i]+=b[i]; //获取回文
}
for (int i = 1;i<=a[0];i++){
a[i+1]+=a[i]/n; //进位
a[i]%=n;
}
if(a[a[0]+1])a[0]++;
for (int i = a[0];i>=1;i--){
printf("%d ",a[i]);
}
printf("\n");
}
int echo(){ //判断回文
int yes = 1;
for (int i = 1;i<=a[0]/2;i++){
if (a[i]!=a[a[0]-i+1]) {
yes = 0;
break;
}
}
return yes;
}
int main(){
scanf("%d",&n);
while (getchar()!='\n') continue;
char c;
while ((c=getchar())!='\n'){
for (int i = a[0];i>=1;i--){
a[i+1]=a[i];
}
if (c>='0'&&c<='9'){
a[1]=c-48;
}
if (c>='A'&&c<='Z'){
a[1]=c-'A'+10;
}
a[0]++;
}
int step;
for (step = 1;step<=30;step++){
highplusecho();
if(echo()) break;
}
if(step <= 30) printf("STEP=%d",step);
else printf("Impossible!");
return 0;
}```