happy_lazier @ 2023-11-23 22:00:46
#include<bits/stdc++.h>
int x[500];
int mid[500];
int j=0;
char M[101];
int N;
using namespace std;
int huiwenshu(int x[]){
for(int i=0;i<j/2;i++){
if(x[i]!=x[j-1-i])return 0;
}
return 1;
}
void fanadd(int x[]){
int y[500];
for(int i=0;i<j;i++){
y[i]=x[j-1-i];
}
for(int i=0;i<j;i++){
x[i]=x[i]+y[i];
if(x[i]>=N){
x[i+1]++;
x[i]=x[i]-N;
}
if(x[j]!=0)j++;
}
}
int main(){
cin>>N;
cin>>M;
while(M[j]!='\0'){
mid[j]=M[j]-'0';
if(M[j]<='F'&&M[j]>='A')mid[j]=M[j]-'A'+10;
j++;
}
for(int i=0;i<j;i++){
x[i]=mid[j-1-i];
}
int step=0;
while(step<=30&&!huiwenshu(x)){
fanadd(x);
step++;
}
if(huiwenshu(x))cout<<"STEP="<<step;
else cout<<"Impossible!";
}
by Disjoint_cat @ 2023-11-23 22:08:13
int y[500];
这里没赋初值,所以 UB 了。
改成
int y[500]={0};
就可以了。
@happy_xiaowan
by LeiSai_AC @ 2023-11-23 22:08:24
liu
by happy_lazier @ 2023-11-23 22:22:52
@Donotplaygame 改了实例也正确了感谢感谢