題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=866&page=show_problem&problem=4953
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #include <iostream> #include <stack>
using namespace std;
int main(){ int n; string cmd, name; stack<string> slept; cin >> n; while(n--){ cin >> cmd; if(cmd == "Sleep"){ cin >> name; slept.push(name); } else if(cmd == "Test"){ if(!slept.empty()) cout << slept.top() << '\n'; else cout << "Not in a dream\n"; } else{ if(!slept.empty()) slept.pop(); } } return 0; }
|