题解 | #堆栈的使用#
堆栈的使用
https://www.nowcoder.com/practice/e91982a145944ceab6bb9a4a508e0e26
#include <iostream> #include <stack> using namespace std; int main(){ int n; string str,data; while(cin>>n){ stack<string> s; for(int i = 0; i < n; i++){ cin>>str; if(str == "P"){ cin>>data; s.push(data); } else if(str == "A"){ if(s.empty()) cout<<'E'<<endl; else{ // char tmp = ; cout<<s.top()<<endl; } } else if(str == "O"){ if(!s.empty()){ s.pop(); } } } } }