求助:为什么把第10、11行合并写为while(n--)会报超时
查看原帖
求助:为什么把第10、11行合并写为while(n--)会报超时
1009774
ingridli楼主2023/5/18 21:05
#include<iostream>
#include<deque>
#include<string>
using namespace std;
int main(){
    long t;
    int n,q;
    deque<long> nums;
    cin>>n;
    while(n>0){
        n--;
        cin>>q;
        if(q==1){cin>>t;nums.push_back(t);}
        else if(q==2){
            if(nums.empty())cout<<"ERR_CANNOT_POP\n";
            else nums.pop_front();
        }
        else if(q==3){
            if(nums.empty()) cout<<"ERR_CANNOT_QUERY\n";
            else cout<<nums.front()<<endl;
        }
        else cout<<nums.size()<<endl;
    }
    return 0;
}
2023/5/18 21:05
加载中...