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
53 0
UVa389 - Basically Speaking
UVa389 - Basically Speaking
40 0
|
机器学习/深度学习
1257:Knight Moves 2021-01-09
1257:Knight Moves 2021-01-09
The 15th Chinese Northeast Collegiate Programming Contest C. Vertex Deletion(树形dp)
The 15th Chinese Northeast Collegiate Programming Contest C. Vertex Deletion(树形dp)
115 0
|
定位技术
German collegiate programming contest 2012 - Ski Jumping
首先用动能定理算出平抛的初速度v0,然后分三种情况,0~L/2,L/2~L,L~无穷远。
139 0
German collegiate programming contest 2012 - Ski Jumping
|
Java
HDU - 2018 Multi-University Training Contest 2 - 1004: Game
HDU - 2018 Multi-University Training Contest 2 - 1004: Game
106 0
|
TensorFlow 算法框架/工具 Python
Taking advantage of context features
In the featurization tutorial we incorporated multiple features beyond just user and movie identifiers into our models, but we haven't explored whether those features improve model accuracy.
208 0
|
数据库
When Tech Meets Love – Smarter Ways to NOT be Single
It’s that time of year again. Single’s Day (a.k.a Double 11) is just around the corner, people buying gifts for loved ones.
1634 0
When Tech Meets Love – Smarter Ways to NOT be Single
|
机器学习/深度学习 算法
917:Knight Moves
题目链接:http://noi.openjudge.cn/ch0205/917/ 原题应该是hdu 1372 总时间限制: 1000ms  内存限制: 65536kB 描述 BackgroundMr Somurolov, fabulous chess-gamer indeed, asserts ...
1051 0