edward0815 @ 2024-04-19 19:35:14
#include <bits/stdc++.h>
using namespace std;
string n1;
int ans=0,a[1001],b[1001],c[1001],m,n[1001],a1[1001],b1[1001],tmp;
int main() {
cin>>m>>n1;
for (int i = n1.length() - 1, j = 0; i >= 0; i--, j++){
n[i]=n1[j]-'0';
}
for (int i = n1.length() - 1, j = 0; i >= 0; i--, j++){
a1[i]=n[i];
b1[i]=n[j];
if(a1[i]!=b1[i]){
tmp++;
}
}
for(int x=1;x<=30;x++){
if(tmp==0){
if(ans!=0){
ans++;
}
cout<<"STEP="<<ans;
return 0;
}
tmp=0;
for (int i = n1.length() - 1, j = 0; i >= 0; i--, j++){
a[i]= n[i];
b[i]=n[j];
}
for (int i = 0; i < n1.length(); i++) {
c[i] += a[i] + b[i];
c[i + 1] = c[i] / m;//模拟进位
c[i] %= m;
n[i]=c[i];
}
for (int i = 0; i < n1.length(); i++) {
c[i]=0;
}
for (int i = n1.length() - 1, j = 0; i >= 0; i--, j++){
a1[i]=n[i];
b1[i]=n[j];
if(a1[i]!=b1[i]){
tmp++;
}
}
ans++;
}
cout<<"Impossible!";
return 0;
}
哪里不对?
by edward0815 @ 2024-04-24 20:13:15
AC了