看板 C_and_CPP 關於我們 聯絡資訊
題目: 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
firejox:所謂的改進是指什麼...IO優化?算法優化?... 10/16 18:22
譬如說 程式流程 結構化 coding寫法 ※ 編輯: k0783154 來自: 210.242.49.84 (10/16 18:23)
Yshuan:c++的話 不考慮包成class嗎? 10/16 18:26
firejox:在存大數時先把無意義的'0'先去除 那只是輸出時才需要的.. 10/16 18:26
Yshuan:嗯 正要說一直-48 不太好... 10/16 18:28
firejox:還有在加之前 先把sign flag乘每一位數 然後加 10/16 18:30
Yshuan:然後一正一負作減法可以拉出來寫成function 10/16 18:30
firejox:接下來在進位即可 10/16 18:31
firejox:我覺得說std::vector without limitation 很有問題... 10/16 18:36
firejox:這是不可能的事情... 10/16 18:37
tropical72:架構感覺很.. 特別. 10/16 18:42
soniclin:without limitation<--因為他沒把題目打完整 10/16 23:35
soniclin:limitation是指char array的30位數限制 10/16 23:36
soniclin:vector版本是拿掉30位數的限制 10/16 23:36
loveme00835:好奇樓上是....? 10/16 23:51
firejox:這個跟30位數限制有啥關聯...= =? 10/17 00:09