Advertisement
LOVEGUN

Bac Science 2020 (Probleme)

May 26th, 2021
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.26 KB | None | 0 0
  1. Program robot;
  2. Uses Wincrt;
  3. Var
  4.   nl,nc,l,c: Integer;
  5.     ch:string;
  6.  
  7. Function verif (ch:String): Boolean;
  8. Var
  9.   i: Integer;
  10.   test: Boolean;
  11. Begin
  12.   i := 0;
  13.   Repeat
  14.     i := i+1;
  15.     test := ch[i] In ['H','B','D','G'];
  16.   Until (i=Length(ch)) Or (test=False);
  17.   verif := test;
  18. End;
  19.  
  20. Procedure saisie (Var nl,nc,l,c:Integer;Var ch:String);
  21. Var
  22.   i,j: Integer;
  23. Begin
  24.   Repeat
  25.     Write ('Saisir NL et NC: ');
  26.     Readln (nl);
  27.     Readln (nc);
  28.   Until (nl In [1..100]) And (nc In [1..100]);
  29.   Repeat
  30.     Write ('Saisir la position de départ: ');
  31.     Readln (l);
  32.     Readln (c);
  33.   Until (1<l) And (l<nl) And (1<c) And (c<nc);
  34.   Repeat
  35.     Write ('Saisir le parcours du robot: ');
  36.     Readln (ch);
  37.   Until verif (ch);
  38. End;
  39.  
  40. Procedure traitement (ch:String;nl,nc,l,c:Integer);
  41. Var
  42. i:integer;
  43. Begin
  44.   i := 0;
  45.   Repeat
  46.     i := i+1;
  47.         case ch[i] Of
  48.             'H':l:=l-1;
  49.             'B':l:=l+1;
  50.             'G':c:=c-1;
  51.             'D':c:=c+1;
  52.         end;
  53.         if (l>nl) or (l<0) or (c<0) or (c>nc) Then
  54.             writeln ('Attention cas de dépassement causé par le pas N°',i);
  55.   Until (i=Length(ch)) or ((l>nl) or (l<0) or (c<0) or (c>nc));
  56.     if (i=Length(ch)) Then
  57.         writeln ('Je suis à la position (',l,',',c,')');
  58. End;
  59. Begin
  60.     saisie (nl,nc,l,c,ch);
  61.     traitement  (ch,nl,nc,l,c);
  62. End.
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement