Odpowiedzi

2009-11-25T17:15:28+01:00
Program TranslateRomanToArabic;

const
aTransTable: array[1..13] of record
AN: word;
RN: string[2];
end = ((AN: 1000; RN:'M'), (AN: 900; RN: 'CM'), (AN: 500; RN: 'D'),
(AN: 400; RN: 'CD'), (AN: 100; RN: 'C'), (AN: 90; RN: 'XC'),
(AN: 50; RN: 'L'), (AN: 40; RN: 'XL'), (AN: 10; RN: 'X'),
(AN: 9; RN: 'IX'), (AN: 5; RN: 'V'), (AN: 4; RN: 'IV'),
(AN: 1; RN: 'I'));


var
RomanNumeral: string;
ArabianNumber: longint;

CurrNum: byte;

CurrSymb: string[2];
CurrVal: word;
begin

repeat begin


Write('Podaj rzymska liczbe: ');
ReadLn(RomanNumeral);

ArabianNumber := 0;
CurrNum := 1;
repeat
CurrSymb := aTransTable[CurrNum].RN;
CurrVal := aTransTable[CurrNum].AN;


while Copy(RomanNumeral, 1, Length(CurrSymb)) = CurrSymb do

begin
Inc(ArabianNumber, CurrVal);
Delete(RomanNumeral, 1, Length(CurrSymb));
end;

Inc(CurrNum);
until RomanNumeral = '';


WriteLn('Arabska liczba: ', ArabianNumber);
WriteLn('Nacisnij ESC aby wyjsc, albo inny klawisz zeby kontynuowac.');
repeat until keypressed;
end;

until readkey=Chr(27);
end.