HDU 1702 ACboy needs your help again

HDU 1702 ACboy needs your help again!

#include<iostream>
#include<queue>
#include<stack>
using namespace std;
stack<int> s;
queue<int> q;
int number;
int main() {
    
    
	int n,l;
	string st,wt;
	cin>>n;
	for(int i=1; i<=n; i++) {
    
    
		cin>>l>>st;
		for(int h=0; h<=999; h++) {
    
    
			if(!q.empty()) {
    
    
				q.pop();
			} else break;
		}
		for(int h=0; h<=999; h++) {
    
    
			if(!s.empty()) {
    
    
				s.pop();
			} else break;
		}
		for(int j=1; j<=l; j++) {
    
    
			if(st=="FIFO") {
    
    //queue
				cin>>wt;
				if(wt=="IN") {
    
    
					cin>>number;
					q.push(number);
				} else {
    
    
					if(!q.empty()) {
    
    
						cout<<q.front()<<endl;
						q.pop();
					}
					else cout<<"None"<<endl;
				}
			} else {
    
    //stack
				cin>>wt;
				if(wt=="IN") {
    
    
					cin>>number;
					s.push(number);
				} else {
    
    
					if(!s.empty()){
    
    
						cout<<s.top()<<endl;
						s.pop();
					}
					else cout<<"None"<<endl;
				}
			}
		}
	}
}

没啥好说的 就是STL

Guess you like

Origin blog.csdn.net/weixin_45446715/article/details/110500036