//java solution to problem 343
import java.util.*;
import java.util.regex.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;
import java.text.*;
class Main
{
public static void main (String args[]) // entry point from OS
{
Main myWork = new Main(); // create a dynamic instance
myWork.Begin(); // the true entry point
}
int findminbase(String s)
{
int i=1,j;
for(char c : s.toCharArray())
{
if(c>='A') j=c-'A'+10;
else j=c-'0';
if(i<j) i=j;
}
i++;
return i;
}
void Begin()
{
String sa,sb,tsa,tsb;
BigInteger a=new BigInteger("0"),b=new BigInteger("0");
int i=0,j=0,m1=2,m2=2;
boolean err=false;
Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter pr=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
try
{
sc=new Scanner(new BufferedReader(new FileReader("INPUT.TXT")));
}
catch(Exception e)
{
System.exit(0);
}
//default delimiter : "\\s+"
// that means spaces , tabs , newlines(form feeds , carriage returns)
// are skipped
while(sc.hasNext())
{
err=false;
sa=sc.next();sb=sc.next();
m1=findminbase(sa);m2=findminbase(sb);
mylabel:
for(i=m1;i<=36;i++)
{
for(j=m2;j<=36;j++)
{
try
{
a=new BigInteger(sa,i);b=new BigInteger(sb,j);
}
catch(Exception ex){continue;}
tsa=a.toString(10);tsb=b.toString(10);
if(tsa.compareTo(tsb)==0) break mylabel;
}
}
if(i>36 && j>36) pr.printf("%s is not equal to %s in any base 2..36%n",sa,sb);
else pr.printf("%s (base %d) = %s (base %d)%n",sa,i,sb,j);
}
pr.close();
sc.close();
}
}
import java.util.*;
import java.util.regex.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;
import java.text.*;
class Main
{
public static void main (String args[]) // entry point from OS
{
Main myWork = new Main(); // create a dynamic instance
myWork.Begin(); // the true entry point
}
int findminbase(String s)
{
int i=1,j;
for(char c : s.toCharArray())
{
if(c>='A') j=c-'A'+10;
else j=c-'0';
if(i<j) i=j;
}
i++;
return i;
}
void Begin()
{
String sa,sb,tsa,tsb;
BigInteger a=new BigInteger("0"),b=new BigInteger("0");
int i=0,j=0,m1=2,m2=2;
boolean err=false;
Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter pr=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
try
{
sc=new Scanner(new BufferedReader(new FileReader("INPUT.TXT")));
}
catch(Exception e)
{
System.exit(0);
}
//default delimiter : "\\s+"
// that means spaces , tabs , newlines(form feeds , carriage returns)
// are skipped
while(sc.hasNext())
{
err=false;
sa=sc.next();sb=sc.next();
m1=findminbase(sa);m2=findminbase(sb);
mylabel:
for(i=m1;i<=36;i++)
{
for(j=m2;j<=36;j++)
{
try
{
a=new BigInteger(sa,i);b=new BigInteger(sb,j);
}
catch(Exception ex){continue;}
tsa=a.toString(10);tsb=b.toString(10);
if(tsa.compareTo(tsb)==0) break mylabel;
}
}
if(i>36 && j>36) pr.printf("%s is not equal to %s in any base 2..36%n",sa,sb);
else pr.printf("%s (base %d) = %s (base %d)%n",sa,i,sb,j);
}
pr.close();
sc.close();
}
}
No comments:
Post a Comment