AlbertMourato

Untitled

Nov 19th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class URI {
  4.     public static int inteiro(String entrada) {
  5.         int retorno = Integer.parseInt(entrada.substring(
  6.                 entrada.lastIndexOf(" ") + 1, entrada.length()));
  7.         return retorno;
  8.     }
  9.  
  10.     public static int anda(String direcao) {
  11.         if (direcao.equals("RIGHT")) {
  12.             return 1;
  13.         }
  14.         if (direcao.equals("LEFT")) {
  15.             return -1;
  16.         }
  17.         return 0;
  18.     }
  19.  
  20.     public static void main(String args[]) {
  21.         Scanner in = new Scanner(System.in);
  22.         int t, n, p = 0, saida, pos;
  23.         String instrucao[] = new String[102];
  24.         t = in.nextInt();
  25.         String entrada = "";
  26.         while (t > 0) {
  27.             saida = 0;
  28.             p = 1;
  29.             n = in.nextInt();
  30.             entrada = in.next();
  31.             for (int i = 0; i < n; i++) {
  32.                 entrada = in.nextLine();
  33.                 if (entrada.length() > 5) {
  34.                     pos = inteiro(entrada);
  35.                     System.out.println(pos);
  36.                     instrucao[p] = instrucao[pos];
  37.                     saida = saida+anda(instrucao[pos]);
  38.                 } else {
  39.                     instrucao[p] = entrada;
  40.                     saida = saida+anda(entrada);
  41.                 }
  42.                 p++;
  43.             }
  44.             System.out.println(saida);
  45.             t--;
  46.         }
  47.  
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment