用栈即可
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main(){
string s;
stack<char>ans;
int a,b;
while(cin>>a>>s>>b){
long number=0;
for(int i=0;i<s.size();i++){//a进制转十进制
int x;
if(s[i]>='a'&&s[i]<='f')x=s[i]-'a'+10;
else if(s[i]>='A'&&s[i]<='F')x=s[i]-'A'+10;
else x=s[i]-'0';
number=number*a+x;
}
while(number!=0){//十进制转b进制
int r=number%b;
number=number/b;
char c;
if(r>9)c=r-10+'A';
else c=r+'0';
ans.push(c);
}
while(!ans.empty()){
printf("%c",ans.top());
ans.pop();
}
printf("\n");
}
}