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;
}
目录
相关文章
UVa11565 - Simple Equations
UVa11565 - Simple Equations
46 0
成功解决 bs4\__init__.py:219: UserWarning: "b'.'" looks like a filename, not markup. You should probably
成功解决 bs4\__init__.py:219: UserWarning: "b'.'" looks like a filename, not markup. You should probably
|
人工智能
P8969 幻梦 | Dream with Dynamic
P8969 幻梦 | Dream with Dynamic
163 0
relocation R_X86_64_PC32 against symbol can not be used when making a shared object recompile with
relocation R_X86_64_PC32 against symbol can not be used when making a shared object recompile with
642 0
HDOJ 1096 A+B for Input-Output Practice (VIII)
HDOJ 1096 A+B for Input-Output Practice (VIII)
97 0
HDOJ 1095 A+B for Input-Output Practice (VII)
HDOJ 1095 A+B for Input-Output Practice (VII)
98 0
How to Detect and Respond to Malware-Free Intrusions
http://www.crowdstrike.com/beyond-malware-how-to-detect-and-respond-to-malware-free-intrusions/...
842 0
Lessons Learned from Building and Running MHN, the World's Largest Crowdsourced Honeynet
http://www.irongeek.com/i.php?page=videos/bsidessf2015/112-lessons-learned-from-building-and-r...
730 0