以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  如何可以把數字變成羅馬數字?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=75095)

--  作者:catyin1989
--  发布时间:2015/9/26 17:39:00
--  如何可以把數字變成羅馬數字?
如題
--  作者:yinyb36
--  发布时间:2015/9/26 19:22:00
--  
 跟据罗马数字的规则生成
--  作者:大红袍
--  发布时间:2015/9/28 9:42:00
--  

dim n as integer = 123

Dim arabic() As Integer =  New Integer(13) {}
Dim roman() As String =  New String(13) {}
Dim i As Integer =  0
Dim o As String =  ""

arabic(0) = 1000
arabic(1) = 900
arabic(2) = 500
arabic(3) = 400
arabic(4) = 100
arabic(5) = 90
arabic(6) = 50
arabic(7) = 40
arabic(8) = 10
arabic(9) = 9
arabic(10) = 5
arabic(11) = 4
arabic(12) = 1

roman(0) = "M"
roman(1) = "CM"
roman(2) = "D"
roman(3) = "CD"
roman(4) = "C"
roman(5) = "XC"
roman(6) = "L"
roman(7) = "XL"
roman(8) = "X"
roman(9) = "IX"
roman(10) = "V"
roman(11) = "IV"
roman(12) = "I"

While n > 0
    While n >= arabic(i)
        n = n - arabic(i)
        o = o + roman(i)
    End While
    i = i + 1
End While

msgbox(o)