虚空求调
by cff_0102 @ 2024-03-28 21:44:50
@[LGZX](/user/1043009) 我在网页源代码中试图找到题号...
by Joker_Error_404 @ 2024-03-28 21:45:29
@[cff_0102](/user/542457) 【模板】栈
by int_stl @ 2024-03-28 21:45:42
6!
by chrispang @ 2024-03-28 21:46:39
@[LGZX](/user/1043009)
```cpp
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stack>
#define int unsigned long long
using namespace std;
stack<int> nums;
string command;
int num;
void clearStack(stack<int>& s) {
while (!s.empty()) {
s.pop();
}
}
signed main(void) {
int T, n;
cin >> T;
while (T--) {
cin >> n;
while (n--) {
cin >> command;
if (command == "push") {
cin >> num;
nums.push(num);
}
else if (command == "pop") {
if (!nums.empty()) {
nums.pop();
}
else {
cout << "Empty" << endl;
}
}
else if (command == "query") {
if (!nums.empty()) {
cout << nums.top() << endl;
}
else {
cout << "Anguei!" << endl;
}
}
else if (command == "size") {
cout << nums.size() << endl;
}
}
clearStack(nums);
}
return 0;
}
```
by int_stl @ 2024-03-28 21:47:21
@[int_stl](/user/764666) 啊,怎么快就好了?还得相信像恁一样的老洛谷人啊,蟹蟹
by LGZX @ 2024-03-28 21:52:18
别问我为啥不用clear,用的VS
by LGZX @ 2024-03-28 21:53:26
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
unsigned long long int a[MAXN];
int t;
void push(int n){
a[t++]=n;
}
void pop(){
t--;
}
unsigned long long top(){
return a[t-1];
}
unsigned long long size(){
return t;
}
bool empty(){
return t==0;
}
void clean(){
for(;;){
if(empty()==1){
return ;
}
else{
pop();
}
}
}
int main(){
unsigned long long n,m;
unsigned long long int num;
string s;
cin>>n;
for(int i=0;i<n;i++){
cin>>m;
for(int i=0;i<m;i++){
cin>>s;
if(s=="push"){
cin>>num;
push(num);
}
if(s=="pop"){
if(empty()){
cout<<"Empty"<<endl;
}
else{
pop();
}
}
if(s=="query"){
if(empty()){
cout<<"Anguei!"<<endl;
}
else{
cout<<top()<<endl;
}
}
if(s=="size"){
cout<<size()<<endl;
}
}
clean();
}
}
```
同问
也是【模板】栈
谢谢~
by Lantern_LZY @ 2024-03-29 17:43:39