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. 【Linux部署 · JDK】在linux系统安装jdk

    1,检查是否安装jdk   echo $JAVA_HOME 或者java -version   2,查看操作系统,很明显这是一个相当old的操作系统,i686是32位操作系统.   3,在oracle ...

  2. Cookie常用操作以及属性

    概述 最近项目要用到cookie存储部分用户信息;研究了一下做一下分享 Cookie 是服务器保存在浏览器的一小段文本信息,每个 Cookie 的大小一般不能超过4KB.浏览器每次向服务器发出请求,就 ...

  3. SpringMVC知识点小结

    SpringMVC: 1.SpringMVC和Spring的关系: 软件开发的三层架构: web层[表示层.表现层]---->Service层---->Dao[DataBase Acces ...

  4. spring mvc:属性无法自动注入

    在使用spring mvc 3开发一个项目模块时,遇到这样一个奇怪的问题: 前端页面发送的请求中,所有参数都无法自动注入到指定的@ModelAttribute对象中,经过检查,参数名称与接受对象的属性 ...

  5. Linux io Model

    socket阻塞与非阻塞,同步与异步 作者:huangguisu 1. 概念理解 在进行网络编程时,我们常常见到同步(Sync)/异步(Async),阻塞(Block)/非阻塞(Unblock)四种调 ...

  6. Spring中实现文件上传

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt110 实现图片上传  用户必须能够上传图片,因此需要文件上传的功能.比较常见 ...

  7. iBatis的一个问题

    写了一段查询语句,条件中有一条alarmtype<>'1004'这样的条件,原来是这样写的 <![CATA[ and alarmtype<>'1004']]> 然后 ...

  8. 【★】深入BGP原理和思想【第…

    前言:学思科技术我想说,浅尝辄止,不是天才千万别深钻.和我研究高等数学一样,越深入就会发现越多的问题与不合理之处.尤其对于IT界,算法的最终解释权还是掌握在老外手中,所以对于有些细节,我们" ...

  9. 九度OJ 1013 开门人和关门人

    #include <iostream> #include <string.h> #include <sstream> #include <math.h> ...

  10. 201521123113《Java程序设计》第6周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 1.2 可选:使用常规方法总结其他上课内容. 使用NetB ...