2.进制问题:
原题链接:102627.2.进制问题2026-02-04 14:56:51
发布于:江苏
**n进制转十进制**:
int jinzhi;
string n;
cin>>jinzhi>>n;
long long int l=n.length(),ans=0,p=0;
for(int i=l-1;i>=0;i--){
int temp=n[i];
if(temp>='A' && temp<='Z') ans+=(temp-55)*pow(jinzhi,p);
else ans+=(temp-'0')*pow(jinzhi,p);
p++;
}
cout<<ans;
**十进制转n进制**:
int n,jinzhi;
cin>>n>>jinzhi;
stack <int> stk;
if(n==0) stk.push(0);
while(n){
stk.push(n%jinzhi);
n/=jinzhi;
}
while(stk.size()){
if(stk.top()>9) cout<<char(stk.top()+55);
else cout<<stk.top();
stk.pop();
}
这里空空如也




















有帮助,赞一个