题解 | #【模板】栈#
【模板】栈
https://www.nowcoder.com/practice/104ce248c2f04cfb986b92d0548cccbf
#include <bits/stdc++.h> using namespace std; int main() { stack<int> s; int n; cin>>n; while(n--) { string i; cin>>i; if(i=="push") { int t; cin>>t; s.push(t); } else if(i=="top") { if(s.size()!=0) cout<<s.top()<<endl; else cout<<"error\n"; } else if(i=="pop") { if(s.size()!=0) { int o=s.top(); cout<<o<<endl; s.pop(); } else { cout<<"error\n"; } } } } // 64 位输出请用 printf("%lld")
菜鸟代码,高手勿喷