Program Besoin;
Type
tab = array [1..250] Of string;
tableau = array [1..250] Of longint;
Var
n: integer;
tb,te: tab;
tbu: tableau;
//***************************
Function verifb(ch:String): boolean;
Var
s,i: integer;
test: boolean;
Begin
i := 0;
s := 0;
Repeat
i := i+1;
If ch[i] In ['0'..'9','#'] Then test := true
Else test := false;
If ch[i]='#' Then s := s+1;
Until (i>=length(ch)) Or (Not(test));
verifb := (test) And (s=1);
End;
//***************************
Function veriflength(ch:String): boolean;
Var
test1,test2: boolean;
p: integer;
Begin
p := pos('#',ch);
If length(copy(ch,1,p-1))<=3 Then test1 := true
Else test1 := false;
If length(copy(ch,p+1,length(ch)-p))<=3 Then
test2 := True
Else test2 := false;
veriflength := (test1) And (test2);
End;
//***************************
Function verif(ch:String): boolean;
Var
test: boolean;
i: Integer;
Begin
i := 0;
Repeat
i := i+1;
If ch[i] In ['0'..'9'] Then test := True
Else test := false;
Until (Not(test)) Or (i>=Length(ch));
verif := test;
End;
//***************************
Procedure remplir(Var te,tb:tab;n:integer);
Var
i: integer;
Begin
For i:=1 To n Do
Begin
Repeat
readln(te[i]);
Until (verif(te[i])) And (length(te[i])=6);
End;
For i:=1 To n Do
Begin
Repeat
readln(tb[i]);
Until (verifb(tb[i])) And (veriflength(tb[i]));
End;
End;
//***************************
Procedure generer(tb:tab;Var tbu:tableau;n:integer);
Const
p1 = 80;
p2 = 160;
Var
i,p,ntableaux,ntables,e: integer;
Begin
For i:=1 To n Do
Begin
p := pos('#',tb[i]);
val(copy(tb[i],1,p-1),ntableaux,e);
val(copy(tb[i],p+1,length(tb[i])-p),ntables,e);
tbu[i] := (p1*ntableaux)+(p2*ntables);
End;
End;
//***************************
Procedure afficher(te:tab;tbu:tableau;n:integer);
Var
ch: string;
i: integer;
max: longint;
Begin
max := tbu[1];
For i:=2 To n Do
Begin
If tbu[i]>max Then max := tbu[i];
End;
ch := '';
For i:=1 To n Do
Begin
If max=tbu[i] Then
Begin
ch := ch+te[i]+'-';
End;
End;
delete(ch,length(ch),1);
writeln('le besoin budgétaire le plus élevé est ',max ,' D les écoles concernées sont : ',ch);
End;
//***************************
Begin
Repeat
Write('donner le nombre d''écoles à visiter :');
readln(n);
Until n In [2..250];
remplir(te,tb,n);
generer(tb,tbu,n);
afficher(te,tbu,n);
End.
Inscription à :
Publier les commentaires (Atom)