[Java][hoj]Super Calculator

来源:互联网 发布:sql server 恢复挂起 编辑:程序博客网 时间:2024/05/01 04:40
package jprac;import java.math.*;import java.util.*;public class Main{public static void main(String[] args){BigInteger a,b;String op,sz1,sz2;Scanner cin = new Scanner(System.in);while(cin.hasNext()){//a = cin.nextBigInteger();//op = cin.next();//b = cin.nextBigInteger();sz1=cin.next();op=cin.next();sz2=cin.next();if(sz1.charAt(0)=='+')a=new BigInteger(sz1.substring(1));elsea=new BigInteger(sz1);if(sz2.charAt(0)=='+')b=new BigInteger(sz2.substring(1));elseb=new BigInteger(sz2);if(op.equals("+"))System.out.println(a.add(b));else if(op.equals("-"))System.out.println(a.subtract(b));else if(op.equals("*"))System.out.println(a.multiply(b));else if(op.equals("/")){if(b.equals(BigInteger.ZERO)){System.out.println("Divided by zero.");}else{BigInteger res[] = a.divideAndRemainder(b);System.out.println(res[0] + " " + res[1]);}}else if(op.equals(">")){ if(a.compareTo(b)>0)System.out.println("true");elseSystem.out.println("false");}else if(op.equals("<")){if(a.compareTo(b)<0)System.out.println("true");elseSystem.out.println("false");}else{if(a.equals(b))System.out.println("true");elseSystem.out.println("false");}}}}

熟悉了一下大数功能,但是这个new总让我心存疑虑。。。好吧,Java中不需要delete

为什么非要转成字符串呢。。。HOJ服务器上的环境版本较低。。。

原创粉丝点击