整數轉換成羅馬數字 python
阿新 • • 發佈:2018-12-30
給定一個整數 numnumnum,將整數轉換成羅馬數字。
如 1,2,3,4,51,2,3,4,51,2,3,4,5
對應的羅馬數字分別為I
,II
,III
,IV
,V
等,更詳細的說明見此點選此連結。
輸入格式
第一行輸入一個整數 num(1≤num≤3999)num(1 \leq num \leq 3999)num(1≤num≤3999)。
輸出格式
輸出 numnumnum 對應的羅馬數字。
樣例輸入
123
樣例輸出
CXXIII
c={0:("","I","II","III","IV","V","VI","VII","VIII","IX"),1:("","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"),2:("","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"),3:("","M","MM","MMM")} num=raw_input() num1=int(num) roman=[] roman.append(c[3][num1/1000%10]) roman.append(c[2][num1/100%10]) roman.append(c[1][num1/10%10]) roman.append(c[0][num1%10]) s='' for i in roman: s=s+i print s