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

2

3

4



5

6



7

8

9



10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41
