https://www.acmicpc.net/problem/10845
using System;
using System.Text;
class Queue {
int first;
int last;
int[] queue;
public Queue(int num){
queue = new int[num];
first=0;
last=0;
}
public void push(int num) {
queue[last] = num;
last++;
}
public int pop() {
if(last-first == 0) return -1;
else {
int ans = queue[first];
queue[first] = 0;
first++;
return ans;
}
}
public int size() {
return last-first;
}
public int empty() {
if(last-first == 0) return 1;
else return 0;
}
public int front() {
if(last-first == 0) return -1;
else return queue[first];
}
public int back() {
if(last-first == 0) return -1;
else return queue[last - 1];
}
}
class Program
{
static void Main() {
string st=Console.ReadLine();
StringBuilder sb = new StringBuilder();
int n=int.Parse(st);
Queue t=new Queue(n);
for(int i=0;i<n;i++){
string[] st1=Console.ReadLine().Split();
switch (st1[0]) {
case "push":
t.push(int.Parse(st1[1]));
break;
case "pop":
sb.Append(t.pop()+"\n");
break;
case "size":
sb.Append(t.size()+"\n");
break;
case "empty":
sb.Append(t.empty()+"\n");
break;
case "front":
sb.Append(t.front()+"\n");
break;
case "back":
sb.Append(t.back()+"\n");
break;
}
}
Console.WriteLine(sb.ToString());
}
}