-
Notifications
You must be signed in to change notification settings - Fork 5
/
RobotInstructions.java
38 lines (34 loc) · 1.04 KB
/
RobotInstructions.java
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
package uva;
import java.util.Scanner;
public class RobotInstructions {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n,cont;
String cp;
int t = in.nextInt();
while((t--)!= 0) {
cont = 0;
n = in.nextInt();
int[] instructions = new int[n];
for(int i = 0; i < n; i++) {
cp = in.next();
if(cp.startsWith("L")) {
instructions[i] = -1;
cont--;
} else if(cp.startsWith("R")) {
instructions[i] = 1;
cont++;
} else {
in.next();
int tmp = in.nextInt();
instructions[i] = instructions[tmp-1];
if(instructions[i] == -1)
cont--;
else
cont++;
}
}
System.out.println(cont);
}
}
}