提交时间:2024-06-01 16:18:14
运行 ID: 150186
#include<bits/stdc++.h> using namespace std; 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 funs(int m,string v){ int i,t=0; for(int i=0;i<=v.size();i++){ if(v[i]>='0'&&v[i]<='9') t=t*m+v[i]-48; else if(v[i]>='A'&&v[i]<='F') t=t*m+v[i]-55; else if(v[i]>='a'&&v[i]<='f') t=t*m+v[i]-87; } return t; } int main(){ int k,l; string n; while(cin>>k>>n>>l){ int octn=funs(k,n); string eac=fun(octn,l); cout<<eac<<"\n"; } }