提交时间:2023-12-21 13:58:39

运行 ID: 117030

#include<bits/stdc++.h> using namespace std; int p,r; string n; int solvea(string s){ int x=1,ans=0; for(int i=s.size()-1;i>=0;i--){ if(s[i]>='A'){ ans+=(s[i]-'A'+10)*x; } else ans+=(s[i]-'0')*x; x*=p; } return ans; } string solveb(int t){ string ans=""; while(t!=0){ int f=t%r; t/=r; if(f<10)ans=((char)(f+'0'))+ans; else ans=((char)((f-10)+'A'))+ans; } return ans; } int main(){ while(cin>>p>>n>>r){ int m=solvea(n); string k=solveb(m); cout<<k<<endl; } return 0; }