简单易懂
2026-08-19 22:06:23
发布于:安徽
1阅读
0回复
0点赞
一条条照题面抄就行
#include<bits/stdc++.h>
using namespace std;
int a[114514];//题目纯吓人,根本不会这么大
int top;
int main() {
int m;
int n;
string s;
cin >> m;
while (m--) {
cin >> s;
if (s == "push") {
cin >> n;
a[++top] = n;
} else if (s == "pop") {
if (top > 0) {
cout << "pop " << a[top] << endl;
top--;
} else cout << "pop fail" << endl;
} else if (s == "top") {
if (top > 0)cout << "top = " << a[top] << endl;
else cout << "top fail" << endl;
} else if (s == "size")cout << "size = " << top << endl;
else {
if (top == 0)cout << "yes" << endl;
else cout << "no" << endl;
}
}
return 0;
}
这里空空如也



有帮助,赞一个