提交时间:2024-08-19 22:52:48
运行 ID: 168128
#include<bits/stdc++.h> using namespace std; int to_ten(int x,string s) { long long int relt=0; int len=s.size(); for(int i=0; i<len; i++) { long long int k=pow(x,len-i-1); int t; if(s[i]>='0'&&s[i]<='9') { t=s[i]-'0'; } else { t=10+s[i]-'A'; } relt+=k*t; } return relt; } string to_x(int x,int num) { string relt=""; while (num) { int k=num%x; num=num/x; char c; if(k<10) { c=k+'0'; } else { c='A'+k-10; } relt=c+relt; } return relt; } int main() { int n; string s; cin>> n >>s; int m,num; cin>>m; num=to_ten(n,s); cout<< to_x(m,num); return 0; }