34 lines
981 B
Plaintext
34 lines
981 B
Plaintext
window 1
|
|
|
|
local fn RomantoDecimal( roman as CFStringRef ) as long
|
|
long i, n, preNum = 0, num = 0
|
|
|
|
for i = len(roman) - 1 to 0 step -1
|
|
n = 0
|
|
select ( fn StringCharacterAtIndex( roman, i ) )
|
|
case _"M" : n = 1000
|
|
case _"D" : n = 500
|
|
case _"C" : n = 100
|
|
case _"L" : n = 50
|
|
case _"X" : n = 10
|
|
case _"V" : n = 5
|
|
case _"I" : n = 1
|
|
end select
|
|
if ( n < preNum ) then num = num - n else num = num + n
|
|
preNum = n
|
|
next
|
|
|
|
end fn = num
|
|
|
|
print @" MCMXC = "; fn RomantoDecimal( @"MCMXC" )
|
|
print @" MMVIII = "; fn RomantoDecimal( @"MMVIII" )
|
|
print @" MMXVI = "; fn RomantoDecimal( @"MMXVI" )
|
|
print @"MDCLXVI = "; fn RomantoDecimal( @"MDCLXVI" )
|
|
print @" MCMXIV = "; fn RomantoDecimal( @"MCMXIV" )
|
|
print @" DXIII = "; fn RomantoDecimal( @"DXIII" )
|
|
print @" M = "; fn RomantoDecimal( @"M" )
|
|
print @" DXIII = "; fn RomantoDecimal( @"DXIII" )
|
|
print @" XXXIII = "; fn RomantoDecimal( @"XXXIII" )
|
|
|
|
HandleEvents
|