Java Solution problem "QUEUEEZ - Easy Queue" - sphere online judge spoj

Codigo Java para el problema Queueez - Easy Queue de la pagina Sphere online judge spoj. Esta es una de las multiples propuestas que el juez online acepta.

Java codec for "QUEUEEZ - Easy Queue"

Here you have the Java solution for the Queueez - Easy Queue.
Here yo have the link to the problem http://www.spoj.com/problems/QUEUEEZ/

import java.io.*;
import java.util.*;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
int i =0;
Queue<Integer> cola = new ArrayDeque<>();
while (i <n){
String [] linea = br.readLine().split(" ");
int num = Integer.parseInt(linea[0]);
if (num==1){
cola.offer(Integer.parseInt(linea[1]));
}
else if (num==2 && cola.isEmpty()==false){
cola.poll();
}
else if(num==3){
if (cola.isEmpty()){
out.write("Empty!"+"n");
}else{
out.write(cola.peek()+"n");
}
}
i++;
}
out.flush();
}

}
 Espero que te guste esta propuesta de solución para el ejercicio Easy Queue. No olvides calificar este articulo.

Recomendado:   Crear un menú con categorías en Wordpress
Subir