ACMSGURU 397 - Text Editor
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
#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;
}
}
相关文章
- 【技术种草】cdn+轻量服务器+hugo=让博客“云原生”一下
- CLB运维&运营最佳实践 ---访问日志大洞察
- vnc方式登陆服务器
- 轻松学排序算法:眼睛直观感受几种常用排序算法
- 十二个经典的大数据项目
- 为什么使用 CDN 内容分发网络?
- 大数据——大数据默认端口号列表
- Weld 1.1.5.Final,JSR-299 的框架
- JavaFX 2012:彻底开源
- 提升as3程序性能的十大要点
- 通过凸面几何学进行独立于边际的在线多类学习
- 利用行动影响的规律性和部分已知的模型进行离线强化学习
- ModelLight:基于模型的交通信号控制的元强化学习
- 浅谈Visual Source Safe项目分支
- 基于先验知识的递归卡尔曼滤波的代理人联合状态和输入估计
- 结合网络结构和非线性恢复来提高声誉评估的性能
- 最佳实践丨云开发CloudBase多环境管理实践
- TimeVAE:用于生成多变量时间序列的变异自动编码器
- 具有线性阈值激活的神经网络:结构和算法
- 内网渗透之横向移动 -- 从域外向域内进行密码喷洒攻击