#include #include #include

using namespace std;

int main() { string article; cin >> article;

int N;
cin >> N;

stack<char> left;
stack<char> right;

for (char c : article) {
    right.push(c);
}

while (N--) {
    char operation;
    cin >> operation;
    
    if (operation == 'L') {
        if (!left.empty()) {
            right.push(left.top());
            left.pop();
        }
    } else if (operation == 'D') {
        if (!right.empty()) {
            left.push(right.top());
            right.pop();
        }
    } else if (operation == 'B') {
        if (!left.empty()) {
            left.pop();
        }
    } else if (operation == 'P') {
        char c;
        cin >> c;
        left.push(c);
    }
}

while (!left.empty()) {
    right.push(left.top());
    left.pop();
}

string result;
while (!right.empty()) {
    result += right.top();
    right.pop();
}

cout << result << endl;

return 0;

}

文本编辑器模拟 - C++ 代码实现

原文地址: https://www.cveoy.top/t/topic/qvou 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录