Составить программу преобразования натуральных числе, записанных в римской нумерации, в десятичную систему счисления. На паскале.

3 Окт 2019 в 10:42
168 +1
1
Ответы
1

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.

19 Апр 2024 в 18:40
Не можешь разобраться в этой теме?
Обратись за помощью к экспертам
Гарантированные бесплатные доработки в течение 1 года
Быстрое выполнение от 2 часов
Проверка работы на плагиат
Поможем написать учебную работу
Прямой эфир