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)
58 0
UVA10474 大理石在哪儿 Where is the Marble?
UVA10474 大理石在哪儿 Where is the Marble?
|
机器学习/深度学习
UVA - 10474 Where is the Marble
Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them.
1421 0
|
人工智能 BI 算法
uva 1326 - Jurassic Remains
点击打开链接uva 1326 题意:给定n个由大写字母组成的字符串,选择尽量多的串使得每个大写字母都能出现偶数次 分析: 1 在一个字符串中每个字符出现的次数是无关的,重要的是只是这些次数的奇偶性。
926 0