-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
55 lines (41 loc) · 1.53 KB
/
Copy pathMain.java
File metadata and controls
55 lines (41 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.util.Scanner;
public class Main {
public static Boolean executeTrajetory(Plateau p, Sonda s, String trajetory) {
int i = 0;
while (i < trajetory.length()) {
char c = trajetory.charAt(i);
if (c == 'L' || c == 'R') s.setDirection(s.newDirection(c));
else if (c == 'M') {
int newRow = s.nextPosition()[0];
int newCol = s.nextPosition()[1];
if (!p.positionAllowed(newRow, newCol)) return false;
p.setPosition(s, newRow, newCol);
s.setRow(newRow);
s.setCol(newCol);
}
else {
System.out.println("Command not allowed!");
return false;
}
i++;
}
return true;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int row = input.nextInt();
int col = input.nextInt();
Plateau plateau = new Plateau(row, col);
while (input.hasNext()) {
int x = input.nextInt();
int y = input.nextInt();
char dir = input.next().charAt(0);
Sonda sonda = new Sonda(x, y, dir);
String trajetory = input.next();
if(executeTrajetory(plateau, sonda, trajetory)) {
System.out.println(sonda.getRow() + " " + sonda.getCol() + " " + sonda.getDirection());
}
}
input.close();
}
}