社区讨论

0分,1个TLE其它全是WA

B3614【模板】栈参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mdi6b2x6
此快照首次捕获于
2025/07/25 09:59
7 个月前
此快照最后确认于
2025/07/25 10:01
7 个月前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
stack <int> st;
int t, n;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	while (t--) {
		cin >> n;
		while (n--) {
			string s;
			cin >> s;
			if (s == "Push") {
				int x;
				cin >> x;
				st.push(x);
			}
			else if (s == "pop") {
				if (!st.empty()) st.pop();
				else cout << "Empty" << endl;
			}
			else if (s == "query") {
				if (!st.empty()) cout << st.top() << endl;
				else cout << "Anguei";
			}
			else if (s == "size") {
				cout << st.size();
			}
		}
	}
	while (!st.empty()) {
		cout <<st.top() << " ";
		st.pop();
	}
    return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...