求大佬找错
查看原帖
求大佬找错
490573
Mon_ika楼主2022/7/17 19:46

为什么会WA qwq

#include <bits/stdc++.h>//洛谷B3614【模板】栈
using namespace std;
int main(){
	int t;
	cin >> t;
	stack<int> s;	
	for(int j=1;j<=t;j++){
		int n;
		cin >> n;
		while(!s.empty()){
			s.pop();
		}
		for(int i=1;i<=n;i++){
		    string x;
		    cin >> x;
			if(x == "push"){
				int y;
				cin >> y;
				s.push(y);
			}
			if(x == "pop"){
				if(!s.empty()){
					s.pop();
				}else{
					cout << "Empty" << endl;
				}
			}
			if(x == "query"){
				if(!s.empty()){
					cout << s.top() << endl;
				}else{
					cout << "Anguei!" << endl;
				}
			}
			if(x == "size"){
				cout << s.size() << endl;
			}
		}		
	}

	
	return 0;
}
2022/7/17 19:46
加载中...