UVa343 What Base Is This

简介: UVa343 What Base Is This
#include <stdio.h>#include <string.h>#include <ctype.h>#define N 100#define END 37intmain()
{
charinput1[N], input2[N];
intbase1, base2;
inti;
intmax1, max2;
intnum1, num2;
intflag;
#ifndef ONLINE_JUDGEfreopen("d:\\uva_in.txt", "r", stdin);
#endifwhile (scanf("%s%s", input1, input2) ==2) {
max1=2, max2=2;;
for (i=0; i<strlen(input1); i++) {
if (isdigit(input1[i]) && (input1[i] -'0') >=max1)
max1=input1[i] -'0'+1;
elseif (isalpha(input1[i]) && (input1[i] -'A'+10) >=max1)
max1=input1[i] -'A'+10+1;
        }
for (i=0; i<strlen(input2); i++) {
if (isdigit(input2[i]) && (input2[i] -'0') >=max2)
max2=input2[i] -'0'+1;
elseif (isalpha(input2[i]) && (input2[i] -'A'+10) >=max2)
max2=input2[i] -'A'+10+1;
        }
flag=0;
for (base1=max1; base1<END; base1++) {
for (i=0, num1=0; i<strlen(input1); i++) {
if (isdigit(input1[i]))
num1=num1*base1+ (input1[i] -'0');
elsenum1=num1*base1+ (input1[i] -'A'+10);
            }
for (base2=max2; base2<END; base2++) {
for (i=0, num2=0; i<strlen(input2); i++) {
if (isdigit(input2[i]))
num2=num2*base2+ (input2[i] -'0');
elsenum2=num2*base2+ (input2[i] -'A'+10);
                }
if (num1==num2) {
flag=1;
break;
                } 
elseif (num2>num1)
break;
            }
if (flag)
break;
        }
if (flag) {
printf("%s (base %d) = %s (base %d)\n", input1, base1, input2, base2);
        } else {
printf("%s is not equal to %s in any base 2..36\n", input1, input2);
        }
    }
return0;
}


目录
相关文章
UVa11076 - Add Again
UVa11076 - Add Again
55 0
uva127 "Accordian" Patience
uva127 "Accordian" Patience
42 0
|
人工智能 BI
UVa1554 - Binary Search
UVa1554 - Binary Search
49 0
UVa 374 Big Mod
UVa 374 Big Mod
40 0
|
数据安全/隐私保护
uva11076Add again
View Code 题意:给定n和n个数,求所有的不重复的全排列的对应数字的和。 分析:对于每个数字,在每一位出现的概率相同,那么只算出一位的结果即可。对于每一位,拿出这个数字后剩下的数字的结果,乘以这个数字对应的下标i那么就是权和了。。
631 0
uva 11636Hello World!
点击打开链接uva11636 水题 #include #include #include #include using namespace std; int solve(int n){ int ans = 0; int ...
728 0