Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class L1Q4 {
- public static void main(String[] args) {
- Arquivo arquivo = new Arquivo("L1Q4.in", "L1Q4.out");
- int[] pilha = new int[300000];
- int n = 1, caso = 1, k, tam;
- while (!arquivo.isEndOfFile()) {
- k = arquivo.readInt();
- arquivo.print("Caso #");
- arquivo.print(caso);
- arquivo.print(":");
- tam = 0;
- while (n != 0) {
- n = arquivo.readInt();
- switch (n) {
- case 1:
- int valor = arquivo.readInt();
- pilha[tam] = valor;
- tam++;
- break;
- case 2:
- int x = 0;
- int[] aux = new int[300000];
- if (tam > k) {
- x = k;
- } else {
- x = tam - 1;
- }
- for (int i = 0; i < x; i++) {
- aux[i] = pilha[x - i];
- }
- for (int i = 0, j = x; i < x; i++, j--) {
- pilha[x - j] = aux[i];
- }
- break;
- case 3:
- tam--;
- arquivo.print(" " + pilha[tam]);
- break;
- }
- if (!arquivo.isEndOfFile()) {
- n = 1;
- }
- }
- caso++;
- arquivo.println();
- }
- arquivo.close();
- }
- }
Add Comment
Please, Sign In to add comment