rt,样例过了,代码如下
#include <iostream>
using namespace std;
class Queue{
private:
int a[10001],f = 0,l = 0;
public:
int size(){
return l-f;
}
void push(int x){
a[l++] = x;
}
void pop(){
if(l == f){
throw "ERR_CANNOT_QUERY";
return;
}
f++;
}
int front(){
if(l == f){
throw "ERR_CANNOT_QUERY";
return 0;
}
return a[f];
}
}q;
int n,op,x;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
while(n--){
cin >> op;
if(op == 1){
cin >> x;
q.push(x);
}
else if(op == 2){
try{
q.pop();
}
catch(const char *e){
cout << e << '\n';
}
}
else if(op == 3){
try{
cout << q.front() << '\n';
}
catch(const char *e){
cout << e << '\n';
}
}
else{
cout << q.size() << '\n';
}
}
return 0;
}
一时兴起想搞个异常捕获玩玩
dalao 救我……