提交时间:2024-06-01 16:22:32
运行 ID: 150195
#include<bits/stdc++.h> using namespace std; int Fun(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 Fur(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 K,L; string N; while(cin>>K>>N>>L){ int a=Fun(K,N); string equalN=Fur(a,L); cout<<equalN<<"\n"; } }