25分10以上无法判断,求助!!
查看原帖
25分10以上无法判断,求助!!
1051743
kanqiqin楼主2024/8/9 11:11
#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;
}
2024/8/9 11:11
加载中...