前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ACMSGURU 397 - Text Editor

ACMSGURU 397 - Text Editor

作者头像
Reck Zhang
发布2021-12-05 09:24:03
5140
发布2021-12-05 09:24:03
举报
文章被收录于专栏:Reck ZhangReck Zhang

Preparing Problem

Problem Description

The simplest text editor “Open Word” allows to create and edit only one word. The editor processes keys ‘a’ – ‘z’, and also ‘L’ (to the left) and ‘R’ (to the right). After starting his work the editor immediately creates an empty word and sets its cursor to the left-most position. When one of keys ‘a’ – ‘z’ is pressed, the text editor inserts corresponding symbol just after the cursor. After that a cursor moves one position to the right in such a way that it is placed just after new symbol. When key ‘L’ or ‘R’ is pressed, the cursor moves one position to the left or to the right respectively. If the cursor can’t be moved because it is placed at the left-most or right-most position the command is ignored. Developers of “Open Word” didn’t think about the effectiveness so the editor is working slowly if a lot of keys have been pressed.

Your task is to write a program that can process a sequence of key pressings emulating this editor and output result string.

Input

The input file contains one string which consists of symbols ‘a’ – ‘z’, ‘L’ and ‘R’. The string length is not less than 1 and doesn’t exceed 10^6.

Output

Write a required string to the output file.

Example(s)

sample input

sample output

abLcd

acdb

sample input

sample output

icpLLLLLacmRRRRRRRRRRRRc

acmicpc

Solution

代码语言:javascript
复制
#include <bits/stdc++.h>

int main() {
    std::ios::sync_with_stdio(false);

    std::string input;
    std::cin >> input;

    std::list<char> text;
    auto it = text.begin();
    for(const auto& c : input) {
        if(c == 'L') {
            if(it != text.begin()) {
                it--;
            }
            continue;
        }
        if(c == 'R') {
            if(it != text.end()) {
                it++;
            }
            continue;
        }
        text.insert(it, c);
    }
    for(const auto& c : text) {
        std::cout << c;
    }
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-12-03,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Preparing Problem
    • Problem Description
      • Input
        • Output
          • Example(s)
            • Solution
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档