kanqiqin @ 2024-08-09 11:11:05
#include<bits/stdc++.h>
using namespace std;
int n,t,ans;
string s;
int change(string s){
int sum=0,cnt=0;
for(int i=0;i<s.size();i++){
sum=0;
if(s[i]<='9'&&s[i]>='0'){
sum=(int)(s[i]-'0');
}
if(s[i]<='F'&&s[i]>='A'){
sum=(int)(s[i]-'A'+10);
}
cnt+=sum*pow(n,s.size()-i-1);
}
return cnt;
}
string get(int x){
string answer;
while(x!=0){
if(x%n>=10){
answer+=char(x%n+'A'-10);
}
else{
answer+=char(x%n+'0');
}
x/=n;
}
return answer;
}
bool check(int x){
int y=0,a=x;
while(x!=0){
y=y*10+x%10;
x/=10;
}
if(y==a) return 1;
return 0;
}
int main(){
cin>>n>>s;
for(int i=1;i<=30;i++){
t=change(s);
int t1=t,q=0;
while(t1!=0){
q=q*10+t1%10;
t1/=10;
}
t=t+q;
if(check(t)==1){
printf("STEP=%d",i);
return 0;
}
s=get(t);
}
cout<<"Impossible!";
return 0;
}
by Martin_L @ 2024-08-09 16:48:14
首先,你在加减的时候没考虑到进制问题……
其次,期待你的改善✨
by kanqiqin @ 2024-08-13 11:37:56
谢了