#include<cstdio> #include<cstring> #include<cmath> using namespace std; char a[10000],b[10000]; long long c[10000],d[10000]; long long base(char e[],long long ba) { long long sum=0; for(long long i=0;i<strlen(e);i++) { long long m; if(e[i]>='A'&&e[i]<='Z')m=e[i]-'A'+10; else m=e[i]-'0'; sum=sum*ba+m; } return sum; } int main() { //freopen("output.txt","w",stdout); // freopen("input.txt","r",stdin); while(scanf("%s %s",&a,&b)==2) { long long m1=0,m2=0; for(long long i=0;i<strlen(a);i++) { long long n; if(a[i]>='A'&&a[i]<='Z')n=a[i]-'A'+10; else n=a[i]-'0'; c[i]=n; if(m1<n)m1=n; } for(long long i=0;i<strlen(b);i++) { long long n; if(b[i]>='A'&&b[i]<='Z')n=b[i]-'A'+10; else n=b[i]-'0'; d[i]=n; if(m2<n)m2=n; } long long flag=0; if(m1==0)m1=1; if(m2==0)m2=1; for(int i=m1+1;i<37&&flag==0;i++) { for(int j=m2+1;j<37&&flag==0;j++) { long long m=base(a,i); long long n=base(b,j); // printf("%d %d %d %d %s %s\n",m,n,i,j,a,b); if(m==n){printf("%s (base %d) = %s (base %d)\n",a,i,b,j);flag=1;} } } if(flag==0)printf("%s is not equal to %s in any base 2..36\n",a,b); } return 0; }
Sunday, August 17, 2014
uva : 343 - What Base Is This?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment