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;
}
目录
相关文章
UVa1531 - Problem Bee
UVa1531 - Problem Bee
51 0
UVa11565 - Simple Equations
UVa11565 - Simple Equations
52 0
HDU-1017,A Mathematical Curiosity
HDU-1017,A Mathematical Curiosity
|
机器学习/深度学习 自然语言处理
|
人工智能 Java 安全
HDU 1039 Easier Done Than Said?
Easier Done Than Said? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12751    Accepted Subm...
804 0
uva 100 The 3n+1 problem
题目链接: http://www.programming-challenges.com/pg.php?page=studenthome /* The 3n+1 problem 计算每个数的循环节长度,求给定区间的循环节长度的最大值。 */ #include&lt;iostream&gt; #include&lt;stdio.h&gt; using namespace std;
1165 0
uva 1326 - Jurassic Remains
点击打开链接uva 1326 题意:给定n个由大写字母组成的字符串,选择尽量多的串使得每个大写字母都能出现偶数次 分析: 1 在一个字符串中每个字符出现的次数是无关的,重要的是只是这些次数的奇偶性。
923 0