Guest User

Untitled

a guest
Oct 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. public class L1Q4 {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         Arquivo arquivo = new Arquivo("L1Q4.in", "L1Q4.out");
  6.         int[] pilha = new int[300000];
  7.         int n = 1, caso = 1, k, tam;       
  8.         while (!arquivo.isEndOfFile()) {
  9.             k = arquivo.readInt();
  10.             arquivo.print("Caso #");
  11.             arquivo.print(caso);
  12.             arquivo.print(":");
  13.             tam = 0;
  14.             while (n != 0) {
  15.                 n = arquivo.readInt();
  16.                 switch (n) {
  17.                 case 1:
  18.                     int valor = arquivo.readInt();
  19.                     pilha[tam] = valor;
  20.                     tam++;
  21.                     break;
  22.  
  23.                 case 2:
  24.                     int x = 0;
  25.                     int[] aux = new int[300000];
  26.                     if (tam > k) {
  27.                         x = k;
  28.                     } else {
  29.                         x = tam - 1;
  30.                     }
  31.  
  32.                     for (int i = 0; i < x; i++) {
  33.                         aux[i] = pilha[x - i];
  34.                     }
  35.  
  36.                     for (int i = 0, j = x; i < x; i++, j--) {
  37.                         pilha[x - j] = aux[i];
  38.                     }
  39.  
  40.                     break;
  41.  
  42.                 case 3:
  43.                     tam--;
  44.                     arquivo.print(" " + pilha[tam]);
  45.                     break;
  46.  
  47.                 }
  48.                 if (!arquivo.isEndOfFile()) {
  49.                     n = 1;
  50.                 }
  51.             }
  52.             caso++;
  53.             arquivo.println();
  54.         }
  55.         arquivo.close();
  56.     }
  57. }
Add Comment
Please, Sign In to add comment