#include <iostream> #include <vector> using namespace std; int main() { vector<string> container, undo; //undo数组保存被回滚的字符串 string str; while (cin >> str) { if (str == "undo") { if (!container.empty()) //回滚操作只能发生在container非空的情况下 { undo.push_back(container.back()); container.pop_back(); } } else if (str == "redo") { if (!undo.empty()) //重做操作也只能发生在undo非空的情况下,否则亲测A 40% { container.push_back(undo.back()); undo.pop_back(); } } else // 新字符串出现必须清空undo数组 { undo.clear(); container.push_back(str); } } for (auto &c : container) { cout << c << " "; } return 0; }
全部评论
(4) 回帖