[問題] 大數相加 - 測試+Debug

看板C_and_CPP (C/C++)作者 ( )時間14年前 (2011/10/16 18:18), 編輯推噓5(5010)
留言15則, 5人參與, 最新討論串1/1
題目: A char array can be used to store large integers one digit at a time. For example, the integer 1234 can be stored in the array a by setting a[0]=’1’, a[1]=’2’, a[2]=’3’, a[3]=’4’. Write a program that reads in two positive integers, then outputs the sum of the two integers. The program using std::vector and without limitation. In addition, allow the integers to be negative numbers. 簡單來說就是做無限位數(大數)的加法,允許有負數。 程式網址:https://gist.github.com/1290733 有興趣的板友可以幫我想測資,檢查有無問題。 或者可以建議此程式有無任何改進的空間,小弟蠻需要學習的。 基本上已經完成一些簡單的錯誤偵測 可檢查 1. 輸入0~9以外的數字 2. 開頭為0的數字 ex. 09923, -0827429, 是不合法的. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 210.242.49.84

10/16 18:22, , 1F
所謂的改進是指什麼...IO優化?算法優化?...
10/16 18:22, 1F
譬如說 程式流程 結構化 coding寫法 ※ 編輯: k0783154 來自: 210.242.49.84 (10/16 18:23)

10/16 18:26, , 2F
c++的話 不考慮包成class嗎?
10/16 18:26, 2F

10/16 18:26, , 3F
在存大數時先把無意義的'0'先去除 那只是輸出時才需要的..
10/16 18:26, 3F

10/16 18:28, , 4F
嗯 正要說一直-48 不太好...
10/16 18:28, 4F

10/16 18:30, , 5F
還有在加之前 先把sign flag乘每一位數 然後加
10/16 18:30, 5F

10/16 18:30, , 6F
然後一正一負作減法可以拉出來寫成function
10/16 18:30, 6F

10/16 18:31, , 7F
接下來在進位即可
10/16 18:31, 7F

10/16 18:36, , 8F
我覺得說std::vector without limitation 很有問題...
10/16 18:36, 8F

10/16 18:37, , 9F
這是不可能的事情...
10/16 18:37, 9F

10/16 18:42, , 10F
架構感覺很.. 特別.
10/16 18:42, 10F

10/16 23:35, , 11F
without limitation<--因為他沒把題目打完整
10/16 23:35, 11F

10/16 23:36, , 12F
limitation是指char array的30位數限制
10/16 23:36, 12F

10/16 23:36, , 13F
vector版本是拿掉30位數的限制
10/16 23:36, 13F

10/16 23:51, , 14F
好奇樓上是....?
10/16 23:51, 14F

10/17 00:09, , 15F
這個跟30位數限制有啥關聯...= =?
10/17 00:09, 15F
文章代碼(AID): #1EcgzmDy (C_and_CPP)
文章代碼(AID): #1EcgzmDy (C_and_CPP)