Homework Introduction
栈
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
unsigned long long stk[N], x;
int top, n;
int T;
string s;
int main() {
cin >> T;
while (T--) {
top = 0 ; // 清空栈
cin >> n;
while (n--) {
cin >> s;
if (s == "push") {
cin >> x;
stk[++top] = x;
} else if (s == "pop") {
if (top == 0)
cout << "Empty" << endl;
else
top--;
} else if (s == "query") {
if (top == 0)
cout << "Anguei!" << endl;
else
cout << stk[top] << endl;
} else
cout << top << endl;
}
}
return 0;
}
Problem
Please claim the assignment to see the problems.
- Status
- Live...
- Problem
- 16
- Open Since
- 2025-8-6 0:00
- Deadline
- 2025-8-31 23:59
- Extension
- 24 hour(s)