思路分析
题目大意已经很清晰了。
读过题后,我们可以很清楚的知道:用栈来模拟桌子。
对于每个字符串:若为 READ ,输出栈顶字符串,并移除栈顶元素;否则将字符串压入栈。
AC Code
#include<bits/stdc++.h>
using namespace std;
int Q;
stack<string> stk;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> Q;
while(Q--)
{
string s;
cin >> s;
if (s == "READ")
{
cout << stk.top() << "\n";
stk.pop();
}
else
stk.push(s);
}
return 0;
}