2007年4月2日 星期一

Long Integer Multiplication

Long Integer Multiplication

Problem Description
In this problem、you will implement the multiplication of two integers. The integers
considered in this problem may be very large. Its value may be too large to be stored
in a xed amount of bytes or words in memory. Thus、you cannot use any data type in
any language in this programming contest to store and manipulate the integers. You must
design a proper data structure to store an integer and write all the operations to do the
multiplication of two integers.

Input Format
Input data contains a set of two integers A and B. The last line of the input le contains
two 0's、indicating the end of the input.

Output Format
For each pair of integrs A and B in the input le、print is product C(= A * B).

Sample Input
12345678901234567890123456 111
-2567 111
-111 -12345678901234567890123456
0 0

Sample Output
1370370358037037035803703616
-284937
1370370358037037035803703616

解題原理:
1. 以字串陣列讀入大數後進行處理
2. 將大數每一個數字視為一個字元陣列元素
3. 將兩個大數使用數學乘法相乘

困難度:*

程式下載

原碼下載


參考來源:中山大學 九十二學年度電腦程式設計競賽 試題 Problem 4

沒有留言: