UVa389 - Basically Speaking

简介: UVa389 - Basically Speaking
#include <cstdio>#include <cstring>#include <stack>usingnamespacestd;
#define N 30intmain()
{
charinput[N];
inta, b;
inti;
intlenOfInput;
intsum;
intc;
stack<int>s;
charres[N];
#ifndef ONLINE_JUDGEfreopen("d:\\uva_in.txt", "r", stdin);
#endifwhile (scanf("%s%d%d", input, &a, &b) ==3) {
lenOfInput=strlen(input);
for (i=0, sum=0; i<lenOfInput; i++) {
if (input[i] >='0'&&input[i] <='9')
c=input[i] -'0';
elsec=input[i] -'A'+10;
sum=sum*a+c;
        }
if (sum==0) {
printf("%7s\n", "0");
continue;
        }
while (sum) {
s.push(sum%b);
sum/=b;
        }
c=0;
while (!s.empty()) {
i=s.top();
s.pop();
if (i>=10)
res[c++] =i-10+'A';
elseres[c++] =i+'0';
        }
res[c] ='\0';
if (c>7)
printf("%7s\n", "ERROR");
elseprintf("%7s\n", res);
    }
return0;
}
目录
相关文章
UVa11506 - Angry Programmer(ISAP)
UVa11506 - Angry Programmer(ISAP)
59 0
UVa11565 - Simple Equations
UVa11565 - Simple Equations
53 0
uva127 "Accordian" Patience
uva127 "Accordian" Patience
43 0
|
机器学习/深度学习
|
人工智能 BI 算法
uva 11624 - Fire!
点击打开链接uva 11624 思路:bfs 分析: 1 题目要判断joe是否可以逃出迷宫,如果可以输出最小的时间,否则输出impossible 2 题目明确规定有且仅有一个Joe,但是火的个数是不确定的 3 那么如果没有火,我们只要去求Joe走出迷宫的时间即可。
1036 0