2008-2009 ACM-ICPC, NEERC, Southern Subregional ContestF
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的更多相关文章
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 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 ...
- Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结
第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...
- codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解
秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...
- 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, ...
- 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)
i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...
- 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$ 思路: 定义一个二元组$< ...
- 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing
[链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...
随机推荐
- 启动tomcat错误:Address already in use: JVM_Bind:8081
解决方法: 1.打开任务管理器,关闭掉javaw进程. 2.修改tomcat端口:tomcat/conf/server.xml
- 中科微北斗定位模组ATGM336H简介
36H系列卫星定位模块 产品介绍 ATGM336H是高灵敏度,支持BDS/GPS/GLONASS卫星导航系统的单系统定位,以及任意组合的多系统联合定位的接收机模块.ATGM336H基于本公司自主独立研 ...
- import和require
es6 的 import 语法跟 require 不同,而且 import 必须放在文件的最开始,且前面不允许有其他逻辑代码,这和其他所有编程语言风格一致. import不同与require,它是编译 ...
- js并行加载,顺序执行
js并行加载,顺序执行 <script>运行脚本或加载外部文件时,会阻塞页面渲染,阻塞其他资源的加载.如果页面中需要加载多个js文件,在古老浏览器中性能会比较糟糕. 因此有了最原始的优化原 ...
- vim插件ctags的安装与使用
LINUX系统下看程序或者编程序时,看到一个函数经常需要知道该函数的定义,这时ctags就派上用场了,其安装和使用方法如下: 安装方法: sudo apt-get install ctags (ubu ...
- poj 3694双联通缩点+LCA
题意:给你一个无向连通图,每次加一条边后,问图中桥的数目. 思路:先将图进行双联通缩点,则缩点后图的边就是桥,然后dfs记录节点深度,给出(u,v)使其节点深度先降到同一等级,然后同时降等级直到汇合到 ...
- python--简易购物车实现
目标要求: 1.用户输入购物预算 2.打印商品清单,由用户选择,预算够则购买,不够则提示 3.输入q,退出程序 4.购物结束,显示购买的东西和余额 实现: 1.用列表存储商品及价格信息 2.建立空列表 ...
- 【2017集美大学1412软工实践_助教博客】团队作业4——第一次项目冲刺(Alpha版本)小组 成绩
第四次团队作业成绩公布 题目 团队作业4: http://www.cnblogs.com/happyzm/p/6722264.html 团队成绩 成绩公示如下: 检查项 会议内容 代码签入 心得体会或 ...
- 结对编程1--基于GUI的四则运算题目生成器
最终项目详细代码(coding地址)/李志强的博客/我的详细代码/方言的博客 一.需求分析 1.实现之前项目的功能,如:除了整数之外,还要支持真分数的四则运算,真分数的运算,并且要求能处理用户的输入, ...
- JTable用法-实例
前几篇文章介绍了JTable的基本用法,本文实现一个简单的JTable,算是前文的一个总结,并造福供拷贝党们. Swing-JTable用法-入门 Swing-JTable的渲染器与编辑器使用demo ...