提交时间:2024-07-17 14:41:51

运行 ID: 156478

#include<bits/stdc++.h> using namespace std; int Funs(int n,string s){ int i,t=0; for(i=0;i<=s.size();i++){ if(s[i]>='0'&&s[i]<='9'){ t=t*n+s[i]-48; } else if(s[i]>='A'&&s[i]<='F'){ t=t*n+s[i]-55; } else if(s[i]>='a'&&s[i]<='f'){ t=t*n+s[i]-87; } } return t; } string Fun(int x,int n){ const string a="0123456789ABCDEF"; string s=""; if(x==0){ return "0"; } for(;x>0;x/=n){ s=a[x%n]+s; } return s; } int main(){ int n,l; string str; while(cin>>n>>str>>l){ int octn=Funs(n,str); string equalN=Fun(octn,l); cout<<equalN<<"\n"; } return 0; }