Inception (UVA 13055) by aizu_e
Contest: 3738    RunID: 20173893    Status: Accepted    Date: Sat Oct 14 14:43:24 JST 2017


#include <bits/stdc++.h>
using namespace std;

int main() {
  int T;
  cin >> T;
  stack<string> st;
  while ( T-- ) {
    string q, n;
    cin >> q;
    if ( q[0] == 'S' ) {
      cin >> n;
      st.push(n);
    } else if ( q[0] == 'K' ) {
      if ( st.size() ) st.pop();
    } else if ( q[0] == 'T' ) {
      if ( st.size() ) cout << st.top() << endl;
      else cout << "Not in a dream" << endl;
    }    
  }
}