题解 | 【模板】队列操作
【模板】队列操作
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.List<long> queue =new System.Collections.Generic.List<long>();
for(int i=0;i<q;i++){
string[] num=System.Console.ReadLine().Split();
int op=int.Parse(num[0]);
if (op==1){
int x=int.Parse(num[1]);
queue.Add(x);
}else if(op==2){
if (queue.Count==0){
System.Console.WriteLine("ERR_CANNOT_POP");
}else{
queue.RemoveAt(0);
}
}else if(op==3){
if (queue.Count==0){
System.Console.WriteLine("ERR_CANNOT_QUERY");
}else{
System.Console.WriteLine(queue[0]);
}
}else if(op==4){
System.Console.WriteLine(queue.Count);
}
}
}
}

查看12道真题和解析