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;
}
目录
相关文章
|
6月前
Strange fuction(HDU--2899)
Strange fuction(HDU--2899)
UVa11958 - Coming Home
UVa11958 - Coming Home
47 0
UVa11565 - Simple Equations
UVa11565 - Simple Equations
52 0
Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_ZMCertification", referenced from:解决方法
Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_ZMCertification", referenced from:解决方法
203 0
|
自然语言处理
Reading the Manual: Event Extraction as Definition Comprehension, EMNLP 2020
Reading the Manual: Event Extraction as Definition Comprehension, EMNLP 2020
89 0
Reading the Manual: Event Extraction as Definition Comprehension, EMNLP 2020
HDOJ 1095 A+B for Input-Output Practice (VII)
HDOJ 1095 A+B for Input-Output Practice (VII)
107 0
HDOJ 1094 A+B for Input-Output Practice (VI)
HDOJ 1094 A+B for Input-Output Practice (VI)
108 0
HDOJ 1096 A+B for Input-Output Practice (VIII)
HDOJ 1096 A+B for Input-Output Practice (VIII)
106 0
【HDU 5572 An Easy Physics Problem】计算几何基础
2015上海区域赛现场赛第5题。 题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5572 题意:在平面上,已知圆(O, R),点B、A(均在圆外),向量V。
1036 0
|
机器学习/深度学习 C++