LOVEGUN

Bac 2014 (10h) (Long)

Mar 18th, 2021 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.11 KB | None | 0 0
  1. Program bac2014;
  2. Uses Wincrt;
  3. Type
  4.   tab = Array [1..20,1..20] Of Integer;
  5. Var
  6.   f: Text;
  7.   t: tab;
  8.   n: Integer;
  9.  
  10. Procedure creation (Var f:Text);
  11. Begin
  12.   Assign (f,'c:\bac\result.txt');
  13. End;
  14.  
  15. Function premier (n:Integer): Boolean;
  16. Var
  17.   r,i: Integer;
  18. Begin
  19.   r := 0;
  20.   For i:=1 To n Do
  21.     If (n Mod i =0) Then
  22.       r := r+1;
  23.   premier := r=2;
  24. End;
  25.  
  26. Procedure remplir (Var t:tab;Var n:Integer);
  27. Var
  28.   i,j: Integer;
  29. Begin
  30.   Repeat
  31.     Writeln ('Saisir N: ');
  32.     Readln (n);
  33.   Until (4<n) And (n<20);
  34.   Randomize;
  35.   For i:=1 To n Do
  36.     For j:=1 To n Do
  37.         Repeat
  38.           t[i,j]:=random (100);
  39.         Until (t[i,j] In [2..99]) And (premier(t[i,j]));
  40. End;
  41.  
  42. Function ligne (t:tab;i,j,n:Integer): String;
  43. Var
  44.   test: Boolean;
  45.   ch,ch1: String;
  46. Begin
  47.   ch := '';
  48.   Repeat
  49.     test := t[i,j]>t[i,j+1];
  50.     j := j+1;
  51.   Until (test=False) Or (j+1=n);
  52.   If test=False Then
  53.     Begin
  54.       j := 1;
  55.       Repeat
  56.         test := t[i,j]<t[i,j+1];
  57.         j := j+1;
  58.       Until (test=False) Or (j+1=n);
  59.     End;
  60.   If test Then
  61.     For j:=1 To n Do
  62.       Begin
  63.         Str (t[i,j],ch1);
  64.         ch := ch+ch1+'-';
  65.       End;
  66.   ligne := Copy(ch,1,Length(ch)-1);
  67. End;
  68.  
  69. Function collone (t:tab;i,j,n:Integer): String;
  70. Var
  71.   test: Boolean;
  72.   ch,ch1: String;
  73. Begin
  74.   ch := '';
  75.   Repeat
  76.     test := t[i,j]>t[i+1,j];
  77.     i := i+1;
  78.   Until (test=False) Or (i+1=n);
  79.   If test=False Then
  80.     Begin
  81.       i := 1;
  82.       Repeat
  83.         test := t[i,j]<t[i+1,j];
  84.         i := i+1;
  85.       Until (test=False) Or (i+1=n);
  86.     End;
  87.   If test Then
  88.     For i:=1 To n Do
  89.       Begin
  90.         Str (t[j,i],ch1);
  91.         ch := ch+ch1+'-';
  92.       End;
  93.   collone := Copy(ch,1,Length(ch)-1);
  94. End;
  95.  
  96. Procedure traitement (Var f:Text;t:tab;n:Integer);
  97. Var
  98.   i,j: Integer;
  99. Begin
  100.     rewrite (f);
  101.     For i:=1 To n Do
  102.     Begin
  103.       If ligne (t,i,1,n)<>'' Then
  104.         Writeln(f,'L',i,'*', ligne (t,i,1,n)) ;
  105.       If collone (t,1,i,n)<>'' Then
  106.         Writeln(f,'C',i,'*', collone (t,1,i,n)) ;
  107.     End;
  108.         close (f);
  109. End;
  110. Begin
  111.   creation (f);
  112.   remplir (t,n);
  113.   traitement (f,t,n);
  114. End.
  115.  
Add Comment
Please, Sign In to add comment