Problem Description
I have a very simple problem for you. Given two integers A and B,
your job is to calculate the Sum of A + B.
Input
The first line of the input contains an integer T(1<=T<=20)
which means the number of test cases. Then T lines follow,
each line consists of two positive integers, A and B. Notice
that the integers are very large, that means you should not
process them by using 32-bit integer. You may assume the length
of each integer will not exceed 1000.
Output
For each test case, you should output two lines. The first line
is "Case #:", # means the number of the test case. The second
line is the an equation "A + B = Sum", Sum means the result of
A + B. Note there are some spaces int the equation. Output a
blank line between two test cases.
Sample Input
2
1 2
112233445566778899 998877665544332211
Sample Output
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
Author
Ignatius.L
這道題考我們的是大數(shù)計(jì)算問(wèn)題,也就是說(shuō)一個(gè)超過(guò)我們系統(tǒng)中l(wèi)ong類(lèi)型的數(shù)锐秦,計(jì)算加法的時(shí)候卧蜓,需要我們自己處理這里面的邏輯,但是無(wú)奈间学,java為我們想好了這一切,我們java中內(nèi)置了一個(gè)java.math.BigInteger工具類(lèi),可以直接計(jì)算大數(shù)蔼囊,所有的問(wèn)題都解決咯。
順便說(shuō)一下衣迷,本人喜歡java的原因畏鼓,可能也就是在最開(kāi)始學(xué)編程的時(shí)候,沒(méi)怎么見(jiàn)過(guò)像eclipse一樣的編譯器壶谒,后來(lái)就喜歡上了它云矫,再后來(lái)自己就在學(xué)習(xí)安卓啦,對(duì)java的語(yǔ)法也比較喜歡汗菜,就這樣咯让禀,換句話說(shuō),筆者的c學(xué)的不好陨界,而acm也不支持什么別的語(yǔ)言啦巡揍,那就java吧,但是有的時(shí)候java確實(shí)會(huì)解題時(shí)間長(zhǎng)的問(wèn)題菌瘪,但是這種情況非常的少腮敌,目前已知的很多acm大神也在使用java的~
代碼:
import java.math.BigInteger;
import java.util.Scanner;
public class Main1002 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for (int i = 0; i < n; i++) {
BigInteger a = in.nextBigInteger();
BigInteger b = in.nextBigInteger();
if (i == n - 1)// 輸出格式控制
{
System.out.println("Case " + (i + 1) + ":\r\n" + a +
" + " + b + " = " + a.add(b));
} else {
System.out.println("Case " + (i + 1) + ":\r\n" + a +
" + " + b + " = " + a.add(b) + "\r\n");
}
}
}
}