#include <iostream> #include <cstring> #include <cmath> using namespace std; int nToTen(int n,char num[]){ int len = strlen(num); int ten = 0; int cf=1; for(int i=len-1,k=0;i>=0;i--,k++){ //1.字符1~9转换成数字 if(num[i]>='0'&&num[i]<='9'){ ten+=(num[i]-'0')*cf; }else{//2. 'A'~'F' ten += (num[i]-'A'+10)*cf; } cf=cf*n; } return ten; } void tenToM(int ten,int m,char ans[]) { char tmp[35]={0}; int len = 0; while(ten!=0){ int u=ten%m; ten/m; if(u>=0&&u<=9){ tmp[len]=u+'0'; }else{ tmp[len]=u+'A'-10; } len++; } for(int i=0;i<len;i++){ ans[i]=tmp[len-1-i]; } } int main() { int n,m; char str[35]={0},ans[35]={0}; cin>>n>>str>>m; int ten=nToTen(n,str); tenToM(ten,m,ans); cout<<ansl return 0; }