Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayDeque;
- import java.util.ArrayList;
- import java.util.Scanner;
- /**
- * Created by Сергей on 27.05.2016.
- */
- public class Sol {
- public static void main(String args[])
- {
- class myQueue {
- ArrayDeque<Integer> queue;
- int size;
- myQueue(){
- queue=new ArrayDeque<>();
- size=0;
- }
- String getCommand(String str){
- int length=str.length();
- int k=1;
- int number=0;
- if (str.charAt(0)=='p' && str.charAt(1)=='u'){
- for (int i=length-1;i>=5;i--)
- {
- number=(str.charAt(i)-'0')*k;
- k*=10;
- }
- queue.offer(number);
- size++;
- return "ok";
- }
- if (str.charAt(0)=='p' && str.charAt(1)=='o'){
- if (size==0) return "error";
- else {
- Integer a = queue.poll();
- size--;
- return a.toString();
- }
- }
- if (str.charAt(0)=='f' && str.charAt(1)=='r'){
- if (size==0) return "error";
- else {
- Integer a = queue.peek();
- return a.toString();
- }
- }
- if (str.charAt(0)=='s' && str.charAt(1)=='i'){
- Integer a=size;
- return a.toString();
- }
- if (str.charAt(0)=='c' && str.charAt(1)=='l'){
- size=0;
- queue.clear();
- return "ok";
- }
- if (str.charAt(0)=='e' && str.charAt(1)=='x'){
- return "bye";
- }
- return "WRONG";
- }
- }
- String str;
- Scanner sc=new Scanner(System.in);
- myQueue st=new myQueue();
- do {
- str=sc.nextLine();
- System.out.println(st.getCommand(str));
- }
- while (str!="exit");
- }
- }
Add Comment
Please, Sign In to add comment