Advertisement
LOVEGUN

Bac 2020 (Rework)

May 6th, 2021
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.64 KB | None | 0 0
  1. Program bac2020;
  2. Uses Wincrt;
  3. Var
  4.   f1,f13,f7: Text;
  5. Procedure remplir (Var f1:Text);
  6. Var
  7.   nb,i: Integer;
  8.     n:string;
  9. Begin
  10.   Repeat
  11.     Writeln ('Saisir NB: ');
  12.     Readln (nb);
  13.   Until (nb>=1);
  14.   Rewrite (f1);
  15.   For i:=1 To nb Do
  16.     Begin
  17.       Readln (n);
  18.       Writeln (f1,n);
  19.     End;
  20.   Close (f1);
  21. End;
  22. Function divis13 (n:String): Boolean;
  23. Var
  24.   sg,s,e,v: Integer;
  25. Begin
  26.   s := 0;
  27.   sg := -1;
  28.   While Length(n)>=3 Do
  29.     Begin
  30.       Val (Copy(n,Length(n)-2,3),v,e);
  31.       s := s+v*sg;
  32.       sg := -sg;
  33.       Delete (n,Length(n)-2,3);
  34.     End;
  35.   Val (n,v,e);
  36.   s := s+v*sg;
  37.   divis13 := Abs(s) Mod 13=0;
  38. End;
  39. Function divis7 (n:String): Boolean;
  40. Var
  41. sg,p,e,s,x,i:integer;
  42. ch:string;
  43. Begin
  44.   ch := '132';
  45.   sg := 1;
  46.   While Length(n)>=2 Do
  47.     Begin
  48.       i := 0;
  49.             s := 0;
  50.       Repeat
  51.         i := i+1;
  52.         Val (n[Length(n)],x,e);
  53.         Val (ch[i],p,e);
  54.         s := s+x*p*sg;
  55.         Delete (n,Length(n),1);
  56.         If (i=3) Then
  57.           Begin
  58.             i := 0;
  59.             sg := -sg;
  60.           End;
  61.       Until (n='');
  62.       Str (abs(s),n);
  63.     End;
  64.     divis7:=(n='7') or (n='0');
  65. End;
  66. Procedure traitement (Var f1,f13,f7:Text);
  67. Var
  68.   n: string;
  69. Begin
  70.   Reset (f1);
  71.   Rewrite (f7);
  72.   Rewrite (f13);
  73.   While Not (Eof(f1)) Do
  74.     Begin
  75.       Readln (f1,n);
  76.       If divis7 (n) Then
  77.                 Writeln (f7,n);
  78.       If divis13 (n) Then
  79.         Writeln (f13,n);
  80.     End;
  81.   Close (f1);
  82.   Close (f7);
  83.   Close (f13);
  84. End;
  85. Begin
  86.     Assign (f1,'c:\bac\Nombres.txt');
  87.   Assign (f13,'c:\bac\divis13.txt');
  88.   Assign (f7,'c:\bac\divis7.txt');
  89.     remplir (f1);
  90.     traitement (f1,f13,f7);
  91. End.
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement