AcWing 3438. 数制转换
原题链接
简单
作者:
追梦少年_ML
,
2022-07-06 11:35:24
,
所有人可见
,
阅读 116
#include<bits/stdc++.h>
using namespace std;
int A[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
int main(){
int i,from,to;
string num;
cin>>from>>num>>to;
transform(num.begin(), num.end(), num.begin(), ::toupper);
int sum=0;
for(i=0;i<num.size();i++){
int temp;
if(num[i]>='A'&&num[i]<='F') temp=10+ num[i]-'A';
else temp=num[i]-'0';
sum=sum*from + temp;
}
string res;
while(sum){
int temp=sum%to;
sum/=to;
res.insert(res.begin(),A[temp]);
}
cout<<res<<endl;
return 0;
}