//java solution
import java.util.*;
import java.util.regex.*;
import java.io.*;
import java.awt.*;
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 sa,sb,tsa,tsb,so;long l;
BigInteger a=new BigInteger("0",16),b=new BigInteger("0",16),c=new BigInteger("0",16);
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
l=sc.nextLong();
for(long i=0;i<l;i++)
{
sa=sc.next();so=sc.next();sb=sc.next();
a=new BigInteger(sa,16);b=new BigInteger(sb,16);
if(so.compareTo("+")==0)
{
c=a.add(b);
}
else
{
c=a.subtract(b);
}
tsa=a.toString(2);tsb=b.toString(2);
tsa=String.format("%13s",tsa);
tsb=String.format("%13s",tsb);
tsa=tsa.replace(' ','0');
tsb=tsb.replace(' ','0');
pr.printf("%s %s %s = %s%n",tsa,so,tsb,c.toString(10));
}
pr.close();
sc.close();
}
}
import java.util.*;
import java.util.regex.*;
import java.io.*;
import java.awt.*;
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 sa,sb,tsa,tsb,so;long l;
BigInteger a=new BigInteger("0",16),b=new BigInteger("0",16),c=new BigInteger("0",16);
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
l=sc.nextLong();
for(long i=0;i<l;i++)
{
sa=sc.next();so=sc.next();sb=sc.next();
a=new BigInteger(sa,16);b=new BigInteger(sb,16);
if(so.compareTo("+")==0)
{
c=a.add(b);
}
else
{
c=a.subtract(b);
}
tsa=a.toString(2);tsb=b.toString(2);
tsa=String.format("%13s",tsa);
tsb=String.format("%13s",tsb);
tsa=tsa.replace(' ','0');
tsb=tsb.replace(' ','0');
pr.printf("%s %s %s = %s%n",tsa,so,tsb,c.toString(10));
}
pr.close();
sc.close();
}
}
No comments:
Post a Comment