TOJ 2234 A+B In the Future 解题

TOJ 2234 A+B In the Future 解题

就是高精度的题目
用java做比较简洁
 1 import  java.util. * ;
 2 import  java.math. * ;
 3
 4 public   class  Main  {
 5
 6   public static void main (String[] args) {
 7       Scanner cin=new Scanner (System.in);
 8    while (cin.hasNext())
 9    {
10        String ysa;
11        String ysb;
12        String sa=cin.next();
13        if (sa.charAt(0)=='+')
14            ysa=sa.substring(1);
15        else
16            ysa=sa;
17            
18        BigInteger a=new BigInteger(ysa,16);
19        String sb=cin.next();
20        if (sb.charAt(0)=='+')
21            ysb=sb.substring(1);
22        else
23            ysb=sb;
24        BigInteger b=new BigInteger(ysb,16);
25        
26        if (a.compareTo(b)==0 && a.compareTo(BigInteger.ZERO)==0)
27            break;
28        if (a.compareTo(b)< 0)
29            System.out.println(sa+" "+sb);
30        else
31            System.out.println(sb+" "+sa);
32        BigInteger ans=a.add(b);
33        if (ans.signum()>=0)
34            System.out.print('+');
35        System.out.println(ans.toString(16).toUpperCase());
36      
37    }

38 
39    }

40}
    
41

你可能感兴趣的:(TOJ 2234 A+B In the Future 解题)