Advertisement
LOVEGUN

Bac 2019 (méthode perso)

Mar 5th, 2021 (edited)
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.82 KB | None | 0 0
  1. Program bac2019;
  2. Uses Wincrt;
  3. Type
  4.   pp = Record
  5.     a,b,ppcm: Integer;
  6.   End;
  7.   tab = Array [1..100] Of pp;
  8. Var
  9.   t: tab;
  10.   n: Integer;
  11.  
  12. Procedure remplir (Var t:tab;Var n:Integer);
  13. Var
  14.   i: Integer;
  15. Begin
  16.   Repeat
  17.     Write ('Saisir N: ');
  18.     Readln (n);
  19.   Until (2<=n) And (n<=100);
  20.   For i:=1 To n Do
  21.     With t[i] Do
  22.       Begin
  23.         Repeat
  24.           Write ('Saisir A: ');
  25.           Readln (a);
  26.         Until (0<a) And (a<1000);
  27.         Repeat
  28.           Write ('Saisir B: ');
  29.           Readln (b);
  30.         Until (0<b) And (b<1000);
  31.       End;
  32. End;
  33.  
  34. Function repet (c:String;ch:String): String;
  35. Var
  36.   i,s: Integer;
  37. Begin
  38.   s := 0;
  39.   Repeat
  40.     If Copy(ch,i,Length(c))=c Then
  41.       s := s+1;
  42.     Delete (ch,1,Pos('*',ch));
  43.   Until ch='';
  44.   Str (s,ch);
  45.   repet := ch;
  46. End;
  47.  
  48. Function facteur (a:Integer): String;
  49. Var
  50.   i,e,x: Integer;
  51.   ch,ch1,c: String;
  52. Begin
  53.   i := 1;
  54.   ch1 := '';
  55.   Repeat
  56.     i := i+1;
  57.     If a Mod i =0 Then
  58.       Begin
  59.         a := a Div i;
  60.         Str(i,ch);
  61.         ch1 := ch1+ch+'*';
  62.         i := 1;
  63.       End;
  64.   Until (a Div i=0);
  65.   ch := '';
  66.   Repeat
  67.     c := Copy (ch1,1,Pos('*',ch1)-1);
  68.     ch := ch+c+'_'+repet(c,ch1)+'*';
  69.     Val (repet(c,ch1),x,e);
  70.     Delete (ch1,1,Length(Copy(ch1,1,Pos('*',ch1)))*x);
  71.   Until (ch1='');
  72.   Delete (ch,Length(ch),1);
  73.   facteur := ch;
  74. End;
  75.  
  76. Function puis (a,b:Integer): Integer;
  77. Var
  78.   i,x: Integer;
  79. Begin
  80.   x := a;
  81.   For i:=1 To b-1 Do
  82.     a := a*x;
  83.   puis := a;
  84. End;
  85.  
  86. Function calcul (ch:String): Integer;
  87. Var
  88.   s,a,b,e: Integer;
  89. Begin
  90.   s := 1;
  91.   ch := ch+'*';
  92.   Repeat
  93.     Val (Copy(ch,1,Pos('_',ch)-1),a,e);
  94.     Val (Copy(ch,Pos('_',ch)+1,Pos('*',ch)-Pos('_',ch)-1),b,e);
  95.     If puis(a,b)<>0 Then
  96.       s := s*puis(a,b);
  97.     Delete (ch,1,Pos('*',ch));
  98.   Until (ch='');
  99.   calcul := s;
  100. End;
  101. Function propre (ch1,ch2:String): String;
  102. Var
  103.   ch: String;
  104. Begin
  105.   ch := ch1+'*';
  106.   ch2 := ch2+'*';
  107.   Repeat
  108.     If Pos(Copy(ch2,1,Pos('_',ch2)),ch)=0 Then
  109.       Begin
  110.         ch := ch+Copy(ch2,1,Pos('*',ch2)-1)+'*';
  111.         Delete (ch2,1,Pos('*',ch2));
  112.       End
  113.     Else
  114.       If Copy(ch2,Pos('_',ch2)+1,1)>Copy (ch,Pos(Copy(ch2,1,2),ch)+2,1) Then
  115.         Begin
  116.           Delete (ch,Pos(Copy(ch2,1,2),ch),4);
  117.           ch := ch+Copy(ch2,1,3)+'*';
  118.           Delete (ch2,1,Pos('*',ch2));
  119.         End
  120.     Else
  121.       Delete (ch2,1,Pos('*',ch2));
  122.   Until (ch2='');
  123.   propre := ch;
  124. End;
  125. Procedure traitement (Var t:tab;n:Integer);
  126. Var
  127.   i: Integer;
  128.   ch: String;
  129. Begin
  130.   For i:=1 To n Do
  131.     With t[i] Do
  132.       ppcm := calcul (propre(facteur (a),facteur (b)));
  133. End;
  134. Procedure affiche (t:tab;n:Integer);
  135. Var
  136.   i: Integer;
  137. Begin
  138.   For i:=1 To n Do
  139.     With t[i] Do
  140.       Writeln ('Le PPCM (',a,',',b,') = ',ppcm);
  141. End;
  142. Begin
  143.   remplir (t,n);
  144.   traitement (t,n);
  145.   affiche (t,n);
  146. End.
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement