Advertisement
LOVEGUN

Exercice 4 (Bac Algo 2020)

May 21st, 2021
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.85 KB | None | 0 0
  1. {https://www.kiteb.net/education/informatique/bac/bacinfo2020/bacalgo2020scinfo.pdf}
  2. Program exercice4;
  3. Uses Wincrt;
  4. Type
  5.   mat = Array [1..50,1..50] Of Integer;
  6. Var
  7.   t: mat;
  8.   n: Integer;
  9.   f: Text;
  10.  
  11. Procedure remplir_t (Var n:Integer;Var t:mat);
  12. Var
  13.   i,j: Integer;
  14. Begin
  15.   Repeat
  16.     Writeln ('Saisir N: ');
  17.     Readln (n);
  18.   Until n In [5..50];
  19.   For i:=1 To n Do
  20.     For j:=1 To n Do
  21.       t[i,j] := Random(100);
  22. End;
  23.  
  24. Function max (t:mat;i,n:Integer): String;
  25. Var
  26.   c,m,l: String;
  27.   j,vmax,nc: Integer;
  28. Begin
  29.   vmax := t[i,1];
  30.   nc := 1;
  31.   For j:=1 To n Do
  32.     If (t[i,j]>vmax) Then
  33.       Begin
  34.         vmax := t[i,j];
  35.         nc := j;
  36.       End;
  37.   Str (nc,c);
  38.   Str (i,l);
  39.   Str (vmax,m);
  40.   max := 'Vmax = '+m+', NL = '+l+' et NC = '+c;
  41. End;
  42.  
  43. Procedure remplir_f (Var f:Text;t:mat;n:Integer);
  44. Var
  45.   i: Integer;
  46. Begin
  47.   Rewrite (f);
  48.   For i:=1 To n Do
  49.     Begin
  50.       Writeln (f,max(t,i,n));
  51.       Writeln (max(t,i,n));
  52.     End;
  53.   Close (f);
  54. End;
  55. function freq (var f:text;n:integer):integer;
  56. Var
  57. s,x,e:integer;
  58. ch:string;
  59. Begin
  60.     reset (f);
  61.     s:=0;
  62.     while not (eof(f)) Do
  63.         Begin
  64.             readln (f,ch);
  65.             val (copy(ch,pos('NC',ch)+5,Length(ch)-(pos('NC',ch)+5)+1),x,e);
  66.             if n=x Then
  67.                 s:=s+1;
  68.         end;
  69.     close (f);
  70.     freq:=s;
  71. end;
  72. Procedure traitement (Var f:Text;n:Integer);
  73. Var
  74. i,x,e,max,sh:integer;
  75. ch:string;
  76. t:array [1..50] of integer;
  77. Begin
  78.   reset (f);
  79.     for i:=1 to n Do
  80.     Begin
  81.         readln (f,ch);
  82.         val (copy(ch,pos('NC',ch)+5,Length(ch)-(pos('NC',ch)+5)+1),x,e);
  83.         t[i]:=x;
  84.     end;
  85.     close (f);
  86.     max:=freq(f,t[1]);
  87.     sh:=t[1];
  88.     for i:=2 to n Do
  89.         if (freq(f,t[i])>=max) Then
  90.             begin
  91.                 max:=freq(f,t[i]);
  92.                 sh:=t[i];
  93.             end;
  94.     writeln ('La colonne dominante est ',sh);
  95. End;
  96. Begin
  97.   remplir_t (n,t);
  98.   Assign (f,'c:\bac\maxiiiiiiiii.txt');
  99.   remplir_f (f,t,n);
  100.     traitement (f,n);
  101. End.
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement