#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;
}