Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Roman-numerals-Decode/XPL0/roman-numerals-decode.xpl0
Normal file
27
Task/Roman-numerals-Decode/XPL0/roman-numerals-decode.xpl0
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
string 0; \use zero-terminated strings
|
||||
code CrLf=9, IntOut=11;
|
||||
|
||||
func Roman(Str); \Convert Roman numeral string to decimal value
|
||||
char Str;
|
||||
int I, Val, Val0, Sum;
|
||||
[I:= 0; Sum:= 0; Val0:= 5000;
|
||||
loop [case Str(I) of
|
||||
^M: Val:= 1000;
|
||||
^D: Val:= 500;
|
||||
^C: Val:= 100;
|
||||
^L: Val:= 50;
|
||||
^X: Val:= 10;
|
||||
^V: Val:= 5;
|
||||
^I: Val:= 1
|
||||
other return Sum; \zero string terminator
|
||||
I:= I+1;
|
||||
Sum:= Sum + Val;
|
||||
if Val > Val0 then Sum:= Sum - 2*Val0;
|
||||
Val0:= Val;
|
||||
];
|
||||
];
|
||||
|
||||
[IntOut(0, Roman("MCMXC")); CrLf(0);
|
||||
IntOut(0, Roman("MMVIII")); CrLf(0);
|
||||
IntOut(0, Roman("MDCLXVI")); CrLf(0);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue