Advertisement
LOVEGUN

Bac 2020

Apr 24th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.19 KB | None | 0 0
  1. Program bac2020;
  2. Uses Wincrt;
  3. Type
  4.   tab = Array [1..20] Of Integer;
  5. Var
  6.   f,f7,f13: Text;
  7.  
  8. Procedure creation (Var f,f7,f13:Text);
  9. Begin
  10.   Assign (f,'c:\bac\Nombres.txt');
  11.   Assign (f7,'c:\bac\Divis7.txt');
  12.   Assign (f13,'c:\bac\Divis13.txt');
  13. End;
  14. Function verif (ch:String): Boolean;
  15. Var
  16.   i: Integer;
  17.   test: Boolean;
  18. Begin
  19.   i := 0;
  20.   Repeat
  21.     i := i+1;
  22.     test := ch[i] In ['0'..'9'];
  23.   Until (test=False) Or (i=Length(ch));
  24.   verif := test;
  25. End;
  26. Procedure remplir (Var f:Text);
  27. Var
  28.   i,n: Integer;
  29.   ch: String;
  30. Begin
  31.   Rewrite (f);
  32.   Repeat
  33.     Write ('Saisir le nombre d''entiers à saisirs: ');
  34.     Readln (n);
  35.   Until (1<=n);
  36.   For i:=1 To n Do
  37.     Begin
  38.       Repeat
  39.         Writeln ('Saisir un entier: ');
  40.         Readln (ch);
  41.       Until verif(ch);
  42.       Writeln (f,ch);
  43.     End;
  44.   Close (f);
  45. End;
  46.  
  47. Function divis13 (n:String): Boolean;
  48. Var
  49.   s,sg,v,e: Integer;
  50. Begin
  51.   s := 0;
  52.   sg := -1;
  53.   While Length(n)>=3 Do
  54.     Begin
  55.       Val (Copy(n,Length(n)-2,3),v,e);
  56.       s := s+v*sg;
  57.       sg := -sg;
  58.       Delete (n,Length(n)-2,3);
  59.     End;
  60.   Val (n,v,e);
  61.   s := s+v*sg;
  62.   divis13 := Abs(s) Mod 13=0;
  63. End;
  64.  
  65. Procedure facteur (ch:String;Var t:tab);
  66. Var
  67.   i,n,e: Integer;
  68. Begin
  69.   For i:=1 To Length(ch) Do
  70.     Begin
  71.       Val (ch[i],n,e);
  72.       t[i] := n;
  73.     End;
  74. End;
  75.  
  76. Function divis7 (n:String): Boolean;
  77. Var
  78.   t1,t2: tab;
  79.     x,s,i:integer;
  80. Begin
  81.   t2[1] := 1;
  82.   t2[2] := 3;
  83.   t2[3] := 2;
  84.   t2[4] := -1;
  85.   t2[5] := -3;
  86.   t2[6] := -2;
  87.   Repeat
  88.     x := 0;
  89.     s := 0;
  90.     facteur(n,t1);
  91.     For i:=Length(n) Downto 1 Do
  92.       Begin
  93.         x := x+1;
  94.         If (x>6) Then
  95.           x := 1;
  96.         s := s+t1[i]*t2[x];
  97.       End;
  98.     Str (s,n);
  99.   Until (Length(n)<2);
  100.   divis7 := (s=0) Or (s=7);
  101. End;
  102.  
  103. Procedure traitement (Var f,f7,f13:Text);
  104. Var
  105.   ch: String;
  106. Begin
  107.   Reset (f);
  108.   Rewrite (f7);
  109.   Rewrite (f13);
  110.   While Not (Eof(f)) Do
  111.     Begin
  112.       Readln (f,ch);
  113.       If divis13(ch) Then
  114.         Writeln (f13,ch);
  115.       If divis7(ch) Then
  116.         Writeln (f7,ch);
  117.     End;
  118.   Close (f13);
  119.   Close (f7);
  120.   Close (f);
  121. End;
  122. Begin
  123.   creation (f,f7,f13);
  124.   remplir (f);
  125.     traitement (f,f7,f13);
  126. End.
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement