题解 | 【模板】队列操作
【模板】队列操作
https://www.nowcoder.com/practice/1137c8f6ffac4d5d94cc1b0cb08723f9
public class Program {
public static void Main() {
string line = System.Console.ReadLine();
int q = int.Parse(line);
System.Collections.Generic.Queue<long> queue = new
System.Collections.Generic.Queue<long>();
for (int i = 0; i < q; i++) {
string[] num = System.Console.ReadLine().Split();
int op = int.Parse(num[0]);
if (op == 1) {
long x = long.Parse(num[1]);
queue.Enqueue(x);
} else if (op == 2) {
if (queue.Count == 0) {
System.Console.WriteLine("ERR_CANNOT_POP");
} else {
queue.Dequeue();
}
} else if (op == 3) {
if (queue.Count == 0) {
System.Console.WriteLine("ERR_CANNOT_QUERY");
} else {
System.Console.WriteLine(queue.Peek());
}
} else if (op == 4) {
System.Console.WriteLine(queue.Count);
}
}
}
}
