24 lines
901 B
Plaintext
24 lines
901 B
Plaintext
100 cls : rem 100 home for Applesoft BASIC
|
|
110 roman$ = "MCMXCIX" : print roman$,"=> "; : gosub 170 : print decimal '1999
|
|
120 roman$ = "XXV" : print roman$,"=> "; : gosub 170 : print decimal '25
|
|
130 roman$ = "CMLIV" : print roman$,"=> "; : gosub 170 : print decimal '954
|
|
140 roman$ = "MMXI" : print roman$,"=> "; : gosub 170 : print decimal '2011
|
|
150 end
|
|
160 rem Decode from roman
|
|
170 decimal = 0
|
|
180 predecimal = 0
|
|
190 for i = len(roman$) to 1 step -1
|
|
200 x$ = mid$(roman$,i,1)
|
|
210 if x$ = "M" then n = 1000 : goto 280
|
|
220 if x$ = "D" then n = 500 : goto 280
|
|
230 if x$ = "C" then n = 100 : goto 280
|
|
240 if x$ = "L" then n = 50 : goto 280
|
|
250 if x$ = "X" then n = 10 : goto 280
|
|
260 if x$ = "V" then n = 5 : goto 280
|
|
270 if x$ = "I" then n = 1
|
|
280 if n < predecimal then decimal = decimal-n
|
|
285 if n >= predecimal then decimal = decimal+n
|
|
290 predecimal = n
|
|
300 next i
|
|
310 return
|