LOVEGUN

Suite Robinson

Dec 30th, 2020 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.31 KB | None | 0 0
  1. Program Robin;
  2. Uses Wincrt;
  3. Type
  4.   tab = Array [1..15] Of Integer;
  5. Var
  6. k: Integer;
  7. f: Text;
  8.  
  9. Function compt (t:tab;i:Integer;n:Integer): Integer;
  10. Var
  11.   compteur: Integer;
  12.   x: Integer;
  13.   j: Integer;
  14. Begin
  15.   compteur := 0;
  16.   x := t[i];
  17.   For j:=1 To n Do
  18.     If t[j]=x Then
  19.       compteur := compteur+1;
  20.   compt := compteur;
  21. End;
  22.  
  23. Procedure tableau (Var t:tab;ch:String);
  24. Var
  25. i,x,e:integer;
  26. Begin
  27.   For i:=1 To Length(ch) Do
  28.     Begin
  29.       Val(ch[i],x,e);
  30.       t[i] := x;
  31.     End;
  32. End;
  33.  
  34. Procedure TriBulle (Var Tab:tab;n:Integer) ;
  35. Var
  36.   i, j, t : Integer;
  37. Begin
  38.   For i := N Downto 1 Do
  39.     For j := 2 To i Do
  40.       If Tab[j-1] > Tab[j] Then
  41.         Begin
  42.           t := Tab[j-1];
  43.           Tab[j-1] := Tab[j];
  44.           Tab[j] := t;
  45.         End;
  46. End;
  47. Function comptage (n:Integer;t:tab;ch:String): Integer;
  48. Var
  49.   j: Integer;
  50.   i: Integer;
  51.   nchaine: String;
  52. Begin
  53.   j := 0;
  54.   Str(n,nchaine);
  55.   For i:=1 To Length(ch) Do
  56.     If n=t[i] Then
  57.       j := j+1;
  58.   comptage := j;
  59. End;
  60. Function invers (ch:String): String;
  61. Var
  62.   x: String;
  63.   i: Integer;
  64. Begin
  65.   x := '' ;
  66.   For i:=Length(ch) Downto 1 Do
  67.     Begin
  68.       x := x+Copy(ch,i-1,2);
  69.       Delete (ch,i-1,2);
  70.       i := i-1;
  71.     End;
  72.   invers := x;
  73. End;
  74. Procedure creation (Var f:Text);
  75. Begin
  76.   Assign (f,'c:/bac/result.text');
  77. End;
  78. procedure saisie (var k:integer);
  79. Begin
  80.     Repeat
  81.         writeln ('Saisir k: ');
  82.         readln (k);
  83.     Until (2<=k) and (k<=15);
  84. end;
  85. Procedure traitement (Var f:Text; k:Integer);
  86. Var
  87.   t: tab;
  88.   ch,TEST,TEST1,TEST2,final: String;
  89.     compteur,j,i:integer;
  90. Begin
  91.     rewrite (f);
  92.   ch:='0';
  93.     writeln (f,'0');
  94.     for compteur:=1 to k-1 Do
  95.     begin
  96.         final := '';
  97.         tableau (t,ch);
  98.       TriBulle(t,Length(ch));
  99.       j := 1;
  100.       For i:=1 To Length(ch) Do
  101.         Begin
  102.           Str (comptage (t[i],t,ch),TEST1);
  103.           Str (t[i],TEST2);
  104.           TEST := TEST1+TEST2;
  105.           final := final+TEST;
  106.           If comptage (t[i],t,ch)>1 Then
  107.             i := i+comptage (t[i],t,ch)-1;
  108.         End;
  109.         ch:=invers(final);
  110.         Writeln (f,ch);
  111.     end;
  112.     close (f);
  113. End;
  114.  
  115. Procedure affiche (Var f:Text);
  116. Var
  117.   ch: String;
  118. Begin
  119.     reset(f);
  120.     While Not(Eof(f)) Do
  121.     Begin
  122.       Readln (f,ch);
  123.       Writeln(ch);
  124.     End;
  125.         close (f);
  126. End;
  127. Begin
  128.   creation (f);
  129.     saisie(k);
  130.   traitement (f,k);
  131.   affiche (f);
  132. End.
  133.  
Add Comment
Please, Sign In to add comment