以下是代码:
#include<bits/stdc++.h>
using namespace std;
int t,n;string opt;long long x;
stack<int> s;
void solve(){
scanf("%d",&n);
while(n--){
cin>>opt;
if(opt=="push"){
scanf("%lld",&x);
s.push(x);
}
else if(opt=="pop"){
if(s.empty()) printf("Empty\n");
else s.pop();
}
else if(opt=="query"){
if(s.empty()) printf("Anguei!\n");
else printf("%lld",&s.top());
}
else printf("%d",&s.size());
}
}
int main(){
scanf("%d",&t);
while(t--) solve();
return 0;
}
以下是编译信息:
/tmp/compiler_tuliro_a/src: 在函数‘void solve()’中:
/tmp/compiler_tuliro_a/src:19:29: 警告:格式 ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type*’ {aka ‘int*’} [-Wformat=]
19 | else printf("%lld",&s.top());
| ~~~^ ~~~~~~~~
| | |
| | __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type* {aka int*}
| long long int
| %n
/tmp/compiler_tuliro_a/src:21:34: 错误:单目‘&’的操作数必须是左值
21 | else printf("%d",&s.size());
| ^