LOVEGUN

Exercice Classe

May 21st, 2021 (edited)
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.77 KB | None | 0 0
  1. Program exercice;
  2. Uses Wincrt;
  3. Type
  4.   mat = Array [1..15,1..15] Of Char;
  5. Var
  6.   n: Integer;
  7.   t: mat;
  8.   ch: String;
  9.   f: Text;
  10. Function alphanum (ch:String): Boolean;
  11. Var
  12. i:integer;
  13. test:Boolean;
  14. Begin
  15.   i := 0;
  16.   Repeat
  17.     i := i+1;
  18.     test := Upcase(ch[i]) In ['A'..'Z','0'..'9'] ;
  19.   Until (i=Length(ch)) Or (test=False);
  20.     alphanum:=test;
  21. End;
  22. Procedure saisie (Var n:Integer;Var ch:String);
  23. Var
  24.   x: Integer;
  25. Begin
  26.   Repeat
  27.     Write ('Saisir N: ');
  28.     Readln (n);
  29.   Until (3<n) And (n<15);
  30.   Repeat
  31.     Write ('Saisir la chaine: ');
  32.     Readln (ch);
  33.   Until (Length(ch)<=Sqr(n)) And (alphanum(ch));
  34.   Repeat
  35.     x := Random(27)+64;
  36.     ch := ch+Chr(x);
  37.   Until Length(ch)=Sqr(n);
  38. End;
  39.  
  40. Procedure remplir_t (Var t:mat;ch:String;n:Integer);
  41. Var
  42.   i,j: Integer;
  43. Begin
  44.   For i:=1 To n Do
  45.     For j:=1 To n Do
  46.       t[i,j] := ch[(i*n)-(n-j)]; {relation mathématique utiliser compteur si trop difficile}
  47. End;
  48.  
  49. Function tri (ch:String): String;
  50. Var
  51.   n,i: Integer;
  52.   aux: Char;
  53. Begin
  54.   n := Length(ch);
  55.   Repeat
  56.     For i:=1 To n-1 Do
  57.       If ch[i]>ch[i+1] Then
  58.         Begin
  59.           aux := ch[i];
  60.           ch[i] := ch[i+1];
  61.           ch[i+1] := aux;
  62.         End;
  63.     n := n-1;
  64.   Until (n=0);
  65.   tri := ch;
  66. End;
  67.  
  68. Procedure traitement (Var f:Text;t:mat;n:Integer);
  69. Var
  70.   res: String;
  71.   i,j: Integer;
  72. Begin
  73.   res := '';
  74.   For i:=1 To n Do
  75.     res := res+t[i,i];
  76.   For i:=2 To n Do
  77.     For j:=1 To i-1 Do
  78.       res := res+t[i,j];
  79.   For i:=1 To n-1 Do
  80.     For j:=i+1 To n Do
  81.       res := res+t[i,j];
  82.   Rewrite (f);
  83.   Repeat
  84.     Writeln (f,tri(Copy(res,1,n)));
  85.     Delete (res,1,n);
  86.   Until (res='');
  87.   Close (f);
  88. End;
  89. Begin
  90.   saisie (n,ch);
  91.   remplir_t(t,ch,n);
  92.   Assign (f,'c:\bac\mots.txt');
  93.   traitement (f,t,n);
  94. End.
  95.  
Add Comment
Please, Sign In to add comment