Приветствую Вас Гость | RSS

Delphi заготовки

Воскресенье, 28.04.2024, 01:34
Главная » 2012 » Март » 21

Функция перевода чисел из римского в арабское


Function myodd(s1:integer):integer;
begin
if s1 mod 2 =0 then result:=0
else result:=1;
end;

function RomanToArabic( const romanNumber : string) : integer ;
const
romanChars = 'IVXLCDMvxlcdm?!#' ;
decades : array [0..8] of integer = (
0, 1, 10, 100, 1000, 10000, 100000,
1000000, 10000000) ;
OneFive : array [0..1] of byte = (1, 5) ;
var
newValue, oldValue : integer ;
cIdx, P : byte ;
begin
result := 0;
oldValue := 0 ;
for cIdx := Length(romanNumber) downto 1 do
begin
P := Succ(Pos(romanNumber[cIdx], romanChars)) ;
newValue := OneFive[myodd(p)] * decades[P div 2] ;
if newValue = 0 then
begin
result := -1;
Exit;
end ;
if newValue < oldValue then newValue := - newValue ;
Inc(result, newValue) ;
oldValue := newValue
end ;
end;


Функция перевода чисел из арабских в римские


function Arab2Roman(arab:integer):s ... Читать дальше »
Просмотров: 3692 | Добавил: NetSoftWare | Дата: 21.03.2012 | Комментарии (1)