//java solution
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
}
void Begin()
{
String s,cs;
int b,t;
BigInteger a;
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("F:\\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())
{
b=sc.nextInt();
t=sc.nextInt();
s=sc.next();
try
{
a=new BigInteger(s,b);
cs=a.toString(t).toUpperCase();
pr.printf("%s base %d = %s base %d%n",s,b,cs,t);
}
catch(Exception ex){
pr.printf("%s is an illegal base %d number%n",s,b);
}
}
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
}
void Begin()
{
String s,cs;
int b,t;
BigInteger a;
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("F:\\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())
{
b=sc.nextInt();
t=sc.nextInt();
s=sc.next();
try
{
a=new BigInteger(s,b);
cs=a.toString(t).toUpperCase();
pr.printf("%s base %d = %s base %d%n",s,b,cs,t);
}
catch(Exception ex){
pr.printf("%s is an illegal base %d number%n",s,b);
}
}
pr.close();
sc.close();
}
}
No comments:
Post a Comment