Program S4;
Var
ch : string;
//*************************************
Function valide(ch : String) : boolean;
Var
i : integer;
v : boolean;
Begin
v := Length(ch) <> 0;
For i:=1 To Length(ch) Do
If Not (ch[i] In ['M','D','C','L','X','V','I']) Then
v := false;
valide := v;
End;
//*************************************
Procedure saisie(Var ch : String);
Begin
Repeat
Write('Entrer un nombre en chiffres romains : ');
Readln(ch);
Until valide(ch);
End;
//*************************************
Function romain_decimal(c : char) : integer;
Begin
Case c Of
'I' : romain_decimal := 1;
'V' : romain_decimal := 5;
'X' : romain_decimal := 10;
'L' : romain_decimal := 50;
'C' : romain_decimal := 100;
'D' : romain_decimal := 500;
'M' : romain_decimal := 1000;
End;
End;
//*************************************
Function convert(ch : String) : integer;
Var
i, s, v, v1 : integer;
Begin
s := 0;
For i:=1 To Length(ch) Do
Begin
v := romain_decimal(ch[i]);
If (i < Length(ch)) Then
Begin
v1 := romain_decimal(ch[i + 1]);
If (v < v1) Then
v := -v;
End;
s := s + v;
End;
convert := s;
End;
//*************************************
Begin
Saisie(ch);
Writeln(ch , ' = ', convert(ch));
End.
Inscription à :
Publier les commentaires (Atom)