Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
167084 | 欧阳雨泽 | K进制数转L进制数 | C++ | 通过 | 100 | 1 MS | 264 KB | 744 | 2024-08-19 16:02:19 |
#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; }