UVa355 - The Bases Are Loaded

简介: UVa355 - The Bases Are Loaded
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <stack>usingnamespacestd;
intchange1(chara)
{
if(a>='0'&&a<='9')
returna-'0';
elsereturna-'A'+10;
}
voidsolve(unsignedlonglongn, intk)
{
stack<int>ans;
inttemp;
if(n==0) {
printf("0");
return;
    }
while(n) {
ans.push(n%k);
n/=k;
    }
while(!ans.empty()) {
temp=ans.top();
ans.pop();
if(temp<=9)
printf("%d",temp);
elseprintf("%c",temp-10+'A');
    }
}
intmain()
{
inti, b1, b2, len, t;
charstr[15];
boolflag;
unsignedlonglongsum, k;
while(cin>>b1>>b2) {
cin>>str;
len=strlen(str);
sum=0;
k=1;
flag=true;
for(i=len-1; i>=0; i--) {
t=change1(str[i]);
if( (t>=b1||t<0) ||str[i]=='-') {
cout<<str<<" is an illegal base "<<b1<<" number"<<endl;
flag=false;
break;
            }
sum+=t*k;
k*=b1;
        }
if(flag) {
cout<<str<<" base "<<b1<<" = ";
solve(sum, b2);
cout<<" base "<<b2<<endl;
        }
    }
return0;
}
目录
相关文章
|
13天前
Strange fuction(HDU--2899)
Strange fuction(HDU--2899)
|
2月前
解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
23 5
|
Ubuntu
Ubuntu :relocation R_X86_64_32 against `.rodata‘ can not be used when making a PIE object;
Ubuntu :relocation R_X86_64_32 against `.rodata‘ can not be used when making a PIE object;
2858 0
Ubuntu :relocation R_X86_64_32 against `.rodata‘ can not be used when making a PIE object;
|
9月前
UVa11565 - Simple Equations
UVa11565 - Simple Equations
35 0
Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_ZMCertification", referenced from:解决方法
Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_ZMCertification", referenced from:解决方法
169 0
|
人工智能
P8969 幻梦 | Dream with Dynamic
P8969 幻梦 | Dream with Dynamic
146 0
|
TensorFlow 算法框架/工具 Python
成功解决File "frozen importlib._bootstrap", line 219, in _call_with_frames_removed ImportError: DLL lo
成功解决File "frozen importlib._bootstrap", line 219, in _call_with_frames_removed ImportError: DLL lo
成功解决File "frozen importlib._bootstrap", line 219, in _call_with_frames_removed ImportError: DLL lo
Tutorial: Generate BBox or Rectangle to locate the target obejct
Tutorial: Generate BBox or Rectangle to locate the target obejct      1 clc;close all;clear all; 2 Img=imread('/home/wangxiao/Documents/files/Vis...
1036 0