Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program robot;
- Uses Wincrt;
- Var
- nl,nc,l,c: Integer;
- ch:string;
- Function verif (ch:String): Boolean;
- Var
- i: Integer;
- test: Boolean;
- Begin
- i := 0;
- Repeat
- i := i+1;
- test := ch[i] In ['H','B','D','G'];
- Until (i=Length(ch)) Or (test=False);
- verif := test;
- End;
- Procedure saisie (Var nl,nc,l,c:Integer;Var ch:String);
- Var
- i,j: Integer;
- Begin
- Repeat
- Write ('Saisir NL et NC: ');
- Readln (nl);
- Readln (nc);
- Until (nl In [1..100]) And (nc In [1..100]);
- Repeat
- Write ('Saisir la position de départ: ');
- Readln (l);
- Readln (c);
- Until (1<l) And (l<nl) And (1<c) And (c<nc);
- Repeat
- Write ('Saisir le parcours du robot: ');
- Readln (ch);
- Until verif (ch);
- End;
- Procedure traitement (ch:String;nl,nc,l,c:Integer);
- Var
- i:integer;
- Begin
- i := 0;
- Repeat
- i := i+1;
- case ch[i] Of
- 'H':l:=l-1;
- 'B':l:=l+1;
- 'G':c:=c-1;
- 'D':c:=c+1;
- end;
- if (l>nl) or (l<0) or (c<0) or (c>nc) Then
- writeln ('Attention cas de dépassement causé par le pas N°',i);
- Until (i=Length(ch)) or ((l>nl) or (l<0) or (c<0) or (c>nc));
- if (i=Length(ch)) Then
- writeln ('Je suis à la position (',l,',',c,')');
- End;
- Begin
- saisie (nl,nc,l,c,ch);
- traitement (ch,nl,nc,l,c);
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement