首页 > 奇安信笔试第二题
头像
朴素的红旗
编辑于 2020-08-16 17:17
+ 关注

奇安信笔试第二题

#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) 回帖
加载中...
话题 回帖

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐