Advertisement
LOVEGUN

Proposition Exercice

May 22nd, 2021
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.00 KB | None | 0 0
  1. Program exercice;
  2. Uses Wincrt;
  3. Type
  4.   mat = Array [1..15,1..15] Of Char;
  5. Var
  6.   f: Text;
  7.   m: mat;
  8.   n: Integer;
  9. Procedure creation (Var f:Text);
  10. Begin
  11.   Assign (f,'c:\bac\mots.txt');
  12. End;
  13. Function alphanum (ch:String): Boolean;
  14. Var
  15.   test: Boolean;
  16.   i: Integer;
  17. Begin
  18.   i := 0;
  19.   Repeat
  20.     i := i+1;
  21.     test := Upcase (ch[i]) In ['A'..'Z','0'..'9'];
  22.   Until (test=False) Or (i=Length(ch));
  23.   alphanum := test;
  24. End;
  25. Procedure remplir_m (Var m:mat;Var n:Integer);
  26. Var
  27.   i,j,x: Integer;
  28.   c: Char;
  29.   ch: String;
  30. Begin
  31.   Repeat
  32.     Writeln ('Saisir N: ');
  33.     Readln (n);
  34.   Until n In [3..15];
  35.   Repeat
  36.     Writeln ('Saisir la chaine :');
  37.     Readln (ch);
  38.   Until (alphanum(ch)) And (Length(ch)<=Sqr(n));
  39.   Randomize;
  40.   While (Length(ch)<Sqr(n)) Do
  41.     Begin
  42.       c := Chr(Random(Ord('Z')-Ord('A')+1)+Ord('A'));
  43.       ch := ch+c;
  44.     End;
  45.   x := 0;
  46.   For i:=1 To n Do
  47.     For j:=1 To n Do
  48.       Begin
  49.         x := x+1;
  50.         m[i,j] := ch[x];
  51.       End;
  52. End;
  53.  
  54. Function tri (ch:String): String;
  55. Var
  56.   n,i: Integer;
  57.   aux: Char;
  58. Begin
  59.   n := Length(ch);
  60.   Repeat
  61.     For i:=1 To n-1 Do
  62.       If ch[i]>ch[i+1] Then
  63.         Begin
  64.           aux := ch[i];
  65.           ch[i] := ch[i+1];
  66.           ch[i+1] := aux;
  67.         End;
  68.     n := n-1;
  69.   Until (n=0);
  70.   tri := ch;
  71. End;
  72.  
  73. Procedure remplir_f (Var f:Text;m:mat;n:Integer);
  74. Var
  75. res,mot:string;
  76. i,j:integer;
  77. Begin
  78.   res := '';
  79.   For i:=1 To n Do
  80.     res := res+m[i,i];
  81.   For i:=2 To n Do
  82.     For j:=1 To i-1 Do
  83.       res := res+m[i,j];
  84.   For i:=1 To n-1 Do
  85.     For j:=i+1 To n Do
  86.       res := res+m[i,j];
  87.   Rewrite (f);
  88.   Repeat
  89.     mot := Copy(res,1,n);
  90.     Delete (res,1,n);
  91.     Writeln (f,tri(mot));
  92.   Until (res='');
  93.   Close (f);
  94. End;
  95. Procedure affiche (Var f:Text);
  96. Var
  97.   ch: String;
  98. Begin
  99.   Reset (f);
  100.   While Not (Eof(f)) Do
  101.     Begin
  102.       Readln (f,ch);
  103.       Writeln (ch);
  104.     End;
  105.   Close (f);
  106. End;
  107. Begin
  108.   creation (f);
  109.   remplir_m (m,n);
  110.   remplir_f (f,m,n);
  111.   affiche (f);
  112. End.
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement