Java Solution problem “QUEUEEZ – Easy Queue” – sphere online judge spoj

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

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();
}

}

Java Solution problem “QUEUEEZ – Easy Queue” – sphere online judge spoj
Califica este post

ARTÍCULOS RELACIONADOS

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *