audiofan wrote:
是我誤解了box59...(恕刪)
謝謝 audiofan ... 謝謝 馬赫迪 ...
以前寫 c 很少被挑毛病. 這次居然被嫌最浪費記憶體...
不都一樣是 int * 26 陣列? 不懂耶... 若要省這塊那就要改用指標囉.
算了還是藏拙...
gemini89a wrote:
1.輸入 49 時會出現 XLIX 還是 IL 呢?
2.如果將來要擴充這段程式能處理的數字位數,除了要改 roman_num 外,是不是還得修改 power10?
3.用這種方式能處理的數字最大是多少呢?輸入負數時會出現什麼情況呢?
4.雖然處理的數字位數不多,用到的除法和餘數不是很多... 不過有沒有辦法可以不用到除跟餘數呢?
driftice wrote:
數字轉羅馬一個簡單原則,每位數分開處理,簡單來說
49 = 40 + 9 (不是50-1)
99 = 90 + 9 (不是100-1)
999 = 900 + 90 + 9 (不是1000-1)
這樣一來就很容易了,最直覺的就建表100~900,10~90,1~9
照順序串起來就是了
進階一點
百位數 (M,D,C)
十位數 (C,L,X)
個位數 (X,V,I)
數字部份都是套同一套法則,只是位數不同符號不同而已
例 7=VII,70=LXX,700=DCC 都是該位數 第二符號一個 + 第三符號兩個
所以弄個1~9的取符號表,然後依位數不同,拿不同符號組來取罷了
想到這裡,或許從羅馬數字轉回阿拉伯數字會比較有趣一點...
The subtractive principle (a subtrahend preceding a minuend) may apply:
Only to a numeral (the subtrahend) which is a power of ten (I, X or C).
For example, "VL" is not a valid representation of 45 (XLV is correct).
Only when the subtrahend preceeds a minuend no more than ten times larger.
For example, "IL" is not a valid representation of 49 (XLIX is correct).
Only if any numeral preceeding the subtrahend is at least ten times larger.
For example, "VIX" is not a valid representation of 14 (XIV is correct), and "IIX" is not correct for 8 (VIII is correct).
Only if any numeral following the minuend is smaller than the subtrahend.
For example, "XCL" is not a valid representation of 140 (CXL is correct).
driftice wrote:
不用除法的話就是字串處理啦,讀進來就當字串,不轉成數字
看字串長度決定位數,然後就是一位一位轉換啦
box59453 wrote:
算了還是藏拙...
for(從 1 到 9)
{
if(和前一個字元相同)
累加;
else // 和前一個字元不同
{
輸出剛剛的字母和之前累加的數目;
累加歸零;
}
}
處理最後一個字元,輸出最後一個計數結果;
daniel35 wrote:
這部份的訓練是多寫程式就可以提升的嗎?