Task

Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero.



In Roman numerals:

 1990 is rendered: 1000=M, 900=CM, 90=XC; resulting in MCMXC
 2008 is written as 2000=MM, 8=VIII; or MMVIII
 1666 uses each Roman symbol in descending order: MDCLXVI


DEFINE PTR="CARD"
CARD ARRAY arabic=[1000 900 500 400 100 90 50 40 10 9 5 4 1]
PTR ARRAY roman(13)
 
PROC InitRoman()
  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"
RETURN
 
PROC EncodeRomanNumber(CARD n CHAR ARRAY res)
  BYTE i,len
  CHAR ARRAY tmp
 
  res(0)=0 len=0
  FOR i=0 TO 12
  DO
    WHILE arabic(i)<=n
    DO
      tmp=roman(i)
      SAssign(res,tmp,len+1,len+1+tmp(0))
      len==+tmp(0)
      n==-arabic(i)
    OD
  OD
  res(0)=len
RETURN
 
PROC Main()
  CARD ARRAY data=[1990 2008 5555 1666 3888 3999]
  BYTE i
  CHAR ARRAY r(20)
 
  InitRoman()
  FOR i=0 TO 5
  DO
    EncodeRomanNumber(data(i),r)
    PrintF("%U=%S%E",data(i),r)
  OD
RETURN