Problem F.

Text Editor Input file: stdin Output file: stdout Time limit: 1 second Memory limit: 64 megabytes

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 106 . Output Write a required string to the output file. Examples stdin stdout

abLcd

acdb

icpLLLLLacmRRRRRRRRRRRRc

acmicpc

题意:编辑文档,光标L往左移一位,R往右移一位,字母就在光标前一位输入。

题解:我室友给了我一种方法,挺巧妙,就是用两个栈,一个储存左边的,一个储存右边的。最后再把右边的存入左边就可以。

#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define PI 3.14159265
using namespace std;
const int maxn=1e6+;
const ll inf=0xfffffffffffffff;
char s[maxn],l[maxn],r[maxn];
int n1,n2;
int main()
{
//std::ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
scanf("%s",s);
int len=strlen(s);
for(int i=;i<len;i++)
{
if(s[i]=='L')
{
if(n1)r[n2++]=l[--n1];
}
else if(s[i]=='R')
{
if(n2)l[n1++]=r[--n2];
}
else
{
l[n1++]=s[i];
}
}
while(n2)l[n1++]=r[--n2];
printf("%s\n",l);
return ;
}

还有一种方法就是用双向链表模拟找出前后关系;

#include<bits/stdc++.h>
#define eps 1e-9
#define PI 3.141592653589793
#define bs 1000000007
#define bsize 256
#define MEM(a) memset(a,0,sizeof(a))
typedef long long ll;
const int maxn=1e6+;
using namespace std;
list<char>s;
string a;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie();cout.tie();
cin>>a;
list<char>::iterator it;
it=s.begin();
for(int i=;i<a.size();i++)
{
if(a[i]=='L')
{
if(it!=s.begin())it--;
}
else if(a[i]=='R')
{
if(it!=s.end())it++;
}
else
{
s.insert(it,a[i]);
}
}
it=s.begin();
for(;it!=s.end();it++)cout<<*it;
cout<<endl;
}

题目链接:http://codeforces.com/gym/101504/attachments

2008-2009 ACM-ICPC, NEERC, Southern Subregional ContestF的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  4. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  5. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  6. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...

  7. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  8. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

    A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...

  9. 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing

    [链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...

随机推荐

  1. 使用Jmeter进行http接口测试 ---------成都杀手

    前言: 本文主要针对http接口进行测试,使用Jmeter工具实现. Jmter工具设计之初是用于做性能测试的,它在实现对各种接口的调用方面已经做的比较成熟,因此,本次直接使用Jmeter工具来完成对 ...

  2. java的jar包加密

    由于项目要求(虽然我觉得代码没什么机密可言...),写好的jar包需要做一定加密处理 这里提供两种办法,一种奇葩,一种通用 1. 直接修改jar文件: 具体步骤: 在代码中插入一段不会运行的到的代码 ...

  3. zbrush曲面增加厚度

    把曲面增加厚度方便雕刻机雕刻. 可以使用zbrush中的边循环功能. 1.准备好需要增加厚度的曲面,把曲面的边缘调整好,尽量的变得平滑. 2.将模型导入到zbrush中,开启双面显示,以方便观察模型的 ...

  4. poj 3177-3352边双联通

    买一送一啊  3177和3352的区别在于3177数据有重边!但是我先做3177的  那么就直接ctrl+c+v搞3352了~. 题意:给一个无向图,要令每个点之间至少有两条不重合的路,需要至少加多少 ...

  5. C# 委托、匿名方法、lambda简介

    在.NET中,委托,匿名方法和Lambda表达式很容易发生混淆.我想下面的代码能证实这点.下面哪一个First会被编译?哪一个会返回我们需要的结果?即Customer.ID=5.答案是6个First不 ...

  6. 如何解决xshell中无法输入中文的问题

    自从安上了xshell以后,用着那叫一个顺手,美中不足的就是一直无法输入中文.不过,既然学习IT,就要习惯英文嘛~直到--我遇到了脚本,写好一个脚本,必要的注释是少不了的,但是作为一个英文渣渣,我真的 ...

  7. 转:深入Java集合学习系列:HashSet的实现原理

    0.参考文献 深入Java集合学习系列:HashSet的实现原理 1.HashSet概述: HashSet实现Set接口,由哈希表(实际上是一个HashMap实例)支持.它不保证set 的迭代顺序:特 ...

  8. 第二次项目冲刺(Beta阶段)--第七天

    一.站立式会议照片 二.项目燃尽图 三.项目进展 codingnet:https://git.coding.net/tuoxie/chachong-beta.git 1.对项目进行全面的测试 2.继续 ...

  9. 团队作业4——第一次项目冲刺(Alpha版本)第五天

    天气阴转晴 一.Daily Scrum Meeting照片 二.燃尽图 三.项目进展 1.界面 功能界面已经大致完成 实现判断学生答题正误的界面 2.出题方面 实现错题库的构造 四.困难与问题 1.项 ...

  10. 201521123075 《Java程序设计》第4周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. - 了解了多态就是以单一的接口操作多种类型的对象,但是对多态和继承的关系还是有点混乱. - ...