var romanNumeral: string; decimalNum: integer; i: integer;
begin writeln('Enter a roman numeral: '); readln(romanNumeral);
decimalNum := 0;
for i := 1 to length(romanNumeral) do begin if romanNumeral[i] = 'I' then decimalNum := decimalNum + 1 else if romanNumeral[i] = 'V' then begin if i > 1 then begin if romanNumeral[i - 1] = 'I' then decimalNum := decimalNum + 3 else decimalNum := decimalNum + 5; end else decimalNum := decimalNum + 5; end else if romanNumeral[i] = 'X' then begin if i > 1 then begin if romanNumeral[i - 1] = 'I' then decimalNum := decimalNum + 8 else decimalNum := decimalNum + 10; end else decimalNum := decimalNum + 10; end else if romanNumeral[i] = 'L' then begin if i > 1 then begin if romanNumeral[i - 1] = 'X' then decimalNum := decimalNum + 30 else decimalNum := decimalNum + 50; end else decimalNum := decimalNum + 50; end else if romanNumeral[i] = 'C' then begin if i > 1 then begin if romanNumeral[i - 1] = 'X' then decimalNum := decimalNum + 80 else decimalNum := decimalNum + 100; end else decimalNum := decimalNum + 100; end else if romanNumeral[i] = 'D' then begin if i > 1 then begin if romanNumeral[i - 1] = 'C' then decimalNum := decimalNum + 300 else decimalNum := decimalNum + 500; end else decimalNum := decimalNum + 500; end else if romanNumeral[i] = 'M' then begin if i > 1 then begin if romanNumeral[i - 1] = 'C' then decimalNum := decimalNum + 800 else decimalNum := decimalNum + 1000; end else decimalNum := decimalNum + 1000; end; end;
writeln('The decimal equivalent of ', romanNumeral, ' is ', decimalNum); end.
program RomanToDecimal(input, output);
var
romanNumeral: string;
decimalNum: integer;
i: integer;
begin
writeln('Enter a roman numeral: ');
readln(romanNumeral);
decimalNum := 0;
for i := 1 to length(romanNumeral) do
begin
if romanNumeral[i] = 'I' then
decimalNum := decimalNum + 1
else if romanNumeral[i] = 'V' then
begin
if i > 1 then
begin
if romanNumeral[i - 1] = 'I' then
decimalNum := decimalNum + 3
else
decimalNum := decimalNum + 5;
end
else
decimalNum := decimalNum + 5;
end
else if romanNumeral[i] = 'X' then
begin
if i > 1 then
begin
if romanNumeral[i - 1] = 'I' then
decimalNum := decimalNum + 8
else
decimalNum := decimalNum + 10;
end
else
decimalNum := decimalNum + 10;
end
else if romanNumeral[i] = 'L' then
begin
if i > 1 then
begin
if romanNumeral[i - 1] = 'X' then
decimalNum := decimalNum + 30
else
decimalNum := decimalNum + 50;
end
else
decimalNum := decimalNum + 50;
end
else if romanNumeral[i] = 'C' then
begin
if i > 1 then
begin
if romanNumeral[i - 1] = 'X' then
decimalNum := decimalNum + 80
else
decimalNum := decimalNum + 100;
end
else
decimalNum := decimalNum + 100;
end
else if romanNumeral[i] = 'D' then
begin
if i > 1 then
begin
if romanNumeral[i - 1] = 'C' then
decimalNum := decimalNum + 300
else
decimalNum := decimalNum + 500;
end
else
decimalNum := decimalNum + 500;
end
else if romanNumeral[i] = 'M' then
begin
if i > 1 then
begin
if romanNumeral[i - 1] = 'C' then
decimalNum := decimalNum + 800
else
decimalNum := decimalNum + 1000;
end
else
decimalNum := decimalNum + 1000;
end;
end;
writeln('The decimal equivalent of ', romanNumeral, ' is ', decimalNum);
end.