33分求救!!!回复必关!!!
查看原帖
33分求救!!!回复必关!!!
1399141
longxiewen11楼主2025/1/23 14:00

望诸位大佬救救我这个蒟蒻吧!

#include <bits/stdc++.h>
using namespace std;
stack <int> s;
int a, b, e;
string c;

int main() {
	cin >> a;
	for (int i = 1; i <= a; i++) {
		cin >> b;
		for (int j = 1; j <= b; j++) {
			cin >> c;
			if (c == "push") {
				cin >> e;
				s.push(e);
			}
			if (c == "pop") {
				if (s.empty() == 0) {
					s.pop();
				} else {
					cout << "Empty" << "\n";
				}
			}
			if (c == "query") {
				if (s.empty() == 0) {
					cout << s.top() << "\n";
				} else {
					cout << "Anguei!" << "\n";
				}
			}
			if (c == "size") {
				cout << s.size() << "\n";
			}
		}
	}
  return 0;
}
2025/1/23 14:00
加载中...