Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class URI {
- public static int inteiro(String entrada) {
- int retorno = Integer.parseInt(entrada.substring(
- entrada.lastIndexOf(" ") + 1, entrada.length()));
- return retorno;
- }
- public static int anda(String direcao) {
- if (direcao.equals("RIGHT")) {
- return 1;
- }
- if (direcao.equals("LEFT")) {
- return -1;
- }
- return 0;
- }
- public static void main(String args[]) {
- Scanner in = new Scanner(System.in);
- int t, n, p = 0, saida, pos;
- String instrucao[] = new String[102];
- t = in.nextInt();
- String entrada = "";
- while (t > 0) {
- saida = 0;
- p = 1;
- n = in.nextInt();
- entrada = in.next();
- for (int i = 0; i < n; i++) {
- entrada = in.nextLine();
- if (entrada.length() > 5) {
- pos = inteiro(entrada);
- System.out.println(pos);
- instrucao[p] = instrucao[pos];
- saida = saida+anda(instrucao[pos]);
- } else {
- instrucao[p] = entrada;
- saida = saida+anda(entrada);
- }
- p++;
- }
- System.out.println(saida);
- t--;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment