提交时间:2023-08-21 16:25:57
运行 ID: 99039
#include <bits/stdc++.h> using namespace std; stack<char> stk; int main(){ int a,c; string b; while(cin>>a>>b>>c){ int ans = 0; int d = 0; for(int i = b.size()-1;i>=0;i--){ if(b[i]>='A'&&b[i]<='Z'){ ans+=int(b[i]-'A'+10)*pow(a,d); d++; } else { ans+=int(b[i]-'0')*pow(a,d); d++; } } //cout<<ans<<endl; while(ans>0){ int sss = ans%c; // cout<<sss<<" "; if(sss>=10){ stk.push(char(sss-10+'A')); } else stk.push(char(sss+48)); ans = ans/c; } while(!stk.empty()){ cout<<stk.top(); stk.pop(); } cout<<endl; } return 0; }