提交时间:2024-08-19 16:02:19
运行 ID: 167084
#include <bits/stdc++.h> using namespace std; const int N=1e7+10; const int INF=0x3f3f3f3f; int a[5009],w,n,ans,len,p,l; char s[5009],hh; int main(){ while(cin>>w>>s>>n){ len=strlen(s),p=0,l=0; for(int i=len-1;i>=0;i--){ if(s[i]<='z' && s[i]>='a')ans+=(s[i]-'a'+10)*pow(w,p); else if(s[i]<='Z' && s[i]>='A')ans+=(s[i]-'A'+10)*pow(w,p); else if(s[i]<='9' && s[i]>='0')ans+=(s[i]-'0')*pow(w,p); p++; } int l=0; while(ans!=0){ a[++l]=ans%n; ans/=n; } for(int i=l;i>=1;i--){ if(a[i]>=10){ char hh='A'; hh+=a[i]-10; cout<<hh; }else{ cout<<a[i]; } } cout<<"\n"; } return 0; }