时间限制:1000ms
单点时限:1000ms
内存限制:256MB

描述

You must have seen the very famous movie series,"Mission Impossible", from 1 to 4. And "Mission Impossible 5" is now on screen in China. Tom Cruise is just learning programming through my MOOC course, and he wants
a good score. So I made him divulge the story of "Mission Impossible 6".

In "Mission Impossible 6",  Ethan Hunt risks his life to install a mini camera in Bad Boss's room, in order to peep at the work Bad Boss does on his computer. Unfortunately, Bad Boss moves his desk to get more sunshine,
and after that Ethan can't see the computer screen through the camera. Fortunately, Ethan can still see the keyboard. So, Ethan wants to know what Bad Boss writes on his computer by watching Bad Boss's keyboard inputs. That job is neither exciting nor risky,
so it's really impossible for Ethan to accomplish --- that's why Tom Cruise wants to learn programming.

To simplified the problem, we assume that Bad Boss is editing a one line document, and the document consists of only lowercase letters. At first, there are nothing in the text editor window except a caret blinking
at the left-most position (the starting position of the line). When Bad Boss input a lowercase letter, the letter appears at the right side of the caret, and then the caret moves to the right side of the letter just inputted. The text editor can switch between
"insert mode" and "overwrite mode". When it's in "overwrite mode", the newly inputted letter will overwrite the letter which is on the right of the caret(if there is one). If it's in "insert mode", the newly inputted letter will be inserted before the letter
which is originally on the right of the caret.

Besides inputting lowercase letters, Bad Boss can do some operations by inputting some uppercase letters, as described below:

'L' :  Moves the caret toward left by one letter. If the caret is already at the start of the line, then nothing happens.

'R':  Moves the caret toward right by one letter. If the caret is already at the end of the line(it means that there are no letters on the right side of the caret), then nothing happens.

'S':  Switch between "overwrite mode" and "insert mode". At the beginning, it's in "insert mode".

'D':  Delete a letter which is on the right of the caret. If the caret is already at the end of the line, then nothing happens. 'D' also has other effect which is described in 'C' operation below.

'B':  Delete a letter which is on the left of the caret. If the caret is already at the start of the line, then nothing happens.

'C': Copy something to the clipboard. At first , there is nothing in the clipboard, and the "copy status" of the editor is set to "NOTHING". When key 'C' is pressed:

If copy status is "NOTHING", copy status will be changed into "START", and the current position of caret is saved as "copy position 1".

if copy status is "START ", copy status will be changed into "NOTHING" and the letters between current caret position and the saved "copy position 1" will be copied into clipboard(The old content in the clipboard
is replaced). If those two positions are the same, clipboard will be cleared.

Please note that , if any letter except 'L' , 'R' and 'D' is inputted when copy status is "START", copy status will changed into "NOTHING" immediately, not affecting the inputted letter taking its own effect as
mention above. If 'D' is inputted when copy status is "START", copy status will changed into "NOTHING" immediately, and the letters between current caret position and "copy position 1" will be deleted.

'V': Paste the content in the clipboard into the right of the caret. If there is nothing in the clipboard, nothing happens. In "insertion mode", the pasted content is inserted. If it's in "overwrite mode" and there
are k letters in the clipboard, then k letters will be overwrote. In "overwrite mode", if the number of letters on the right side of the caret is less then k, those letters will also all be replaced by the letters in the clipboard. After the paste operation,
the caret moves to the right of the last pasted letter.

The content of the text line will never exceed M letters. Any input which will cause the content exceed M letters must be ignored. Especially, when you paste, you either paste all content in the clipboard, or paste
nothing due to the text length limit.

输入

The first line of the input is a integer T(T <= 20), meaning that there are T test cases. The T lines follow, and each line is a test case.

For each test case:

A integer M (0 <= M <= 10,000) goes first ,meaning the text length limitation. Then some letters follow, describing what Bad Boss inputs. The total number of letters in one test case is no more than 10,000.

输出

For each test case, print the result which Bad Boss gets. If the result is nothing, print "NOTHING".

样例输入
8
100 abcdeLCLLD
5 abcLkjff
15 abcBBdeLLDDxzDDDDRRRR
25 abcdefgLLLSxyzSLLku
20 abcdefgLLCkLLCRRRRRCLV
20 abcdefgLLCkLLCRRRRCLLLSV
30 abcdeCLLCRRVCLRCabVkz
10 abcBBBLB
样例输出
abe
abkjc
axz
abcdxkuyz
abcdekfekfgg
abcdeekfg
abcdedeabkz
NOTHING


题意:

L:光标左移一位,如果光标已经在该行的开始位置,不进行操作。



R:光标右移一位,如果光标已经在该行的结尾位置,不进行操作。



S:“覆盖模式”和“插入模式”之间进行转换。开始的时候在“插入模式”。



D:删除光标右侧一个字母,如果这个字母已经在这行的结尾处,不进行操作。

   D在C操作下右其他功能。



B:删除光标左侧的一个字母,如果这个字母已经在这行的开始,不进行操作。



C:复制东西到剪贴板,起初 没有东西在剪贴板, 编辑器的“复制状态”设置为“NOTHING"。

当C被按下:

1、如果复制状态是“NOTHING”,状态转为“START”,字母的current position被保存位 “copy position 1”。

2、如果复制状态是 “START” 状态转为“NOTHING”,在current position 和copy position 1之间的字母被复制到剪贴板上(剪贴板上的旧内容被覆盖),如果这两个position相同,剪贴板被清空。





当复制状态是“START”,输入任何的字母(除了L 、R 、D), 复制 状态立即会被转成“NOTHING”,不会影响输入字母的本身的效果。 如果“D”被输入,当复制状态是“START”,复制状态会立即转成“NOTHING”,在current position 和copy position 1之间的字母被删除。





V:粘贴剪贴板上的内容到光标的右侧。

1、如果剪贴板上没有东西,不进行操作。

2、在“插入状态”下,粘贴的内容被插入。

3、在“覆盖状态”下,并且有k个字母在剪贴板上,那么k个字母将被重写。在“覆盖状态”下,如果光标右侧的字母数量小于k个,这些字母也会全部被剪贴板中的内容所替代。

4、粘贴操作之后,光标移动到最后粘贴的字母后面。





文本的内容不会超过M个字母,任何会造成内容超过M个字母的输入 必须被忽略。尤其是,当你粘贴的时候,你要么粘贴所有的内容到剪贴板上,要么什么都不粘贴,因为文本长度超过限制。





不知道什么地方,还是有问题,没有A掉,过两天再看看吧。。。

#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define ll long long int
#define maxn 205
#define eps 1e-10
#define mod 1000000007
#define pii pair<int,int>
#define INSERT 0
#define OVER 1
#define NOTHING 0
#define START 1
int main()
{ int Case;
rd(Case);
char ch[10005];
string str;
while(Case--)
{
str="";
int M;
rd(M);
scanf("%s",&ch); int len = strlen(ch);
int carloca=0, Csta=NOTHING,Cpos1=-1, mode = INSERT;
string clipboard="";
for(int i=0; i<len; i++ )
{
if(Csta == START && ch[i]!='L' && ch[i] != 'R' && ch[i] !='D' && ch[i]!='C' ){
Csta = NOTHING;
}
if(ch[i]<='z'&&ch[i]>='a') ///添加字符
{
if(mode == INSERT)
{
if(str.length()+1 <= M){ ///插入模式超出M
string sss="";
sss+=ch[i];
str.insert( carloca,sss);
carloca++;
}
// cout<<str<<"*"<<endl;
}
else ///覆盖模式
{
if(str.length()+1 <= M){
string sss="";
sss+=ch[i];
str.insert(carloca,sss); carloca++;
if(carloca < str.length())
str.replace(carloca, 1, ""); ///删除操作
}
}
}
if(ch[i]<='Z'&&ch[i]>='A')
{
// cout<<Csta<<' ';
switch(ch[i])
{
case 'L' :
if(carloca>0) carloca--;
// cout<<"L <-"<<str<<' '<<carloca<<" ";
break;
case 'R' :
if(carloca<str.length()) carloca++;
// cout<<"R ->"<<str<<"长度:"<<str.length()<<' '<<carloca<<" ";
break;
case 'S' :
if(mode == INSERT) mode = OVER;
else mode = INSERT;
break;
case 'D' :
if(Csta == START ){ ///删除多个字符
Csta = NOTHING;
if(carloca >= Cpos1){ /// 开始 现在 删除前面
str.replace( Cpos1 , carloca - Cpos1, "");///Cpos1,carloca - Cpos1) ;//;str.replace(carloca, carloca - Cpos1 , "");
carloca -= (carloca - Cpos1);
}
else { ///现在位置 开始 删除后面
str.replace( carloca , Cpos1 - carloca , "");
}
}
else{ ///删除单个字母
Csta = NOTHING;
if(carloca < str.length()) str.replace(carloca,1, ""); ///删除操作
}
break;
case 'B' :
///删除单个字母
if(carloca > 0 ) {
str.replace(carloca-1,1, ""); ///删除操作
carloca--;
}
break;
case 'C' :
if(Csta == NOTHING) {
Csta = START;
Cpos1 = carloca ;
}
else{
Csta = NOTHING;
//if(str.length() + ( carloca - Cpos1 ) <= M) ///不超过范围
if(carloca >= Cpos1){ /// 开始 现在
string s(str,Cpos1,carloca - Cpos1) ;//;str.replace(carloca, carloca - Cpos1 , "");
clipboard = s;
// cout<<"clipboard:"<<clipboard<<endl;
}
else { ///现在位置 开始
string s(str,carloca , Cpos1 - carloca);
clipboard = s;
// cout<<"clipboard:"<<clipboard<<endl;
}
//cout<<clipboard<<' ';
}
break;
case 'V' :
if(mode == INSERT){ ///插入模式下粘贴
if(str.length() + clipboard.length() <= M){
// cout<<carloca<<' ';
str.insert( carloca , clipboard );
carloca+=clipboard.length();
}
}
else{ ///覆盖模式下粘贴
//cout<<"clipboard:"<<clipboard<<endl;
// for(int i=0 ;i<clipboard.length();i++){
// if(carloca==M) break;
// string sss="";
// sss+=clipboard[i];
// str.insert(carloca,sss);
//
// carloca++;
// if(carloca < str.length())
// str.replace(carloca, 1, ""); ///删除操作
// } if(str.length() + clipboard.length() - (str.length() - carloca > clipboard.length() ? clipboard.length() : str.length() - carloca) <=M ){
if(str.length() - carloca <= clipboard.length() ) { ///后面的全覆盖
str.replace( carloca , str.length() - carloca,"");
str += clipboard;
carloca = str.length();
}
else{///后面的部分覆盖
str.replace( carloca , clipboard.length() , "");
carloca += clipboard.length();
}
}
}
break;
}
} }
if(str=="") cout<<"NOTHING\n";
cout<<str<<endl;
}
return 0;
}

2015 ACM/ICPC Asia Regional Beijing Online的更多相关文章

  1. hdu 5444 Elven Postman(二叉树)——2015 ACM/ICPC Asia Regional Changchun Online

    Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long ...

  2. (并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )

    http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others)    Memo ...

  3. (二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)

    http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others)  ...

  4. 2015 ACM/ICPC Asia Regional Changchun Online HDU 5444 Elven Postman【二叉排序树的建树和遍历查找】

    Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  5. HDU 5458 Stability(双连通分量+LCA+并查集+树状数组)(2015 ACM/ICPC Asia Regional Shenyang Online)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5458 Problem Description Given an undirected connecte ...

  6. 【二分】【最长上升子序列】HDU 5489 Removed Interval (2015 ACM/ICPC Asia Regional Hefei Online)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5489 题目大意: 一个N(N<=100000)个数的序列,要从中去掉相邻的L个数(去掉整个区间 ...

  7. 【线段树】HDU 5493 Queue (2015 ACM/ICPC Asia Regional Hefei Online)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5493 题目大意: N个人,每个人有一个唯一的高度h,还有一个排名r,表示它前面或后面比它高的人的个数 ...

  8. 【动态规划】HDU 5492 Find a path (2015 ACM/ICPC Asia Regional Hefei Online)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5492 题目大意: 一个N*M的矩阵,一个人从(1,1)走到(N,M),每次只能向下或向右走.求(N+ ...

  9. 【贪心】【模拟】HDU 5491 The Next (2015 ACM/ICPC Asia Regional Hefei Online)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5491 题目大意: 一个数D(0<=D<231),求比D大的第一个满足:二进制下1个个数在 ...

随机推荐

  1. PHP 5.6.11 访问SQL Server2008R2

    PHP天生支持MySQL,但是有时候也想让它访问SQL Server,该怎么办呢? 最近找了点资料,测试成功了PHP访问SQLSvr的几种情况,限于时间,还没有测试更多不同环境,把测试过的记录如下: ...

  2. C#接口作用的深入理解

    1.C#接口的作用 C#接口是一个让很多初学C#者容易迷糊的东西,用起来好像很简单,定义接口,里面包含方法,但没有方法具体实现的代码,然后在继承该接口的类里面要实现接口的所有方法的代码,但没有真正认识 ...

  3. 远程访问linux环境安装图形界面问题解决汇总

    本文内容转摘于其他网页,仅用于学习: 通常Linux出现 DISPLAY 尚未设置 解决方法,在root用户目录下执行#xhost +: [root@TEST144239 ~]# xhost + ac ...

  4. Oracle备份与恢复之exp/imp

    获取帮助 exp help=y/imp help=y 工作方式 交互式 exp 命令行 exp user/pwd@dbname file=/oracle/test.dmp full=y 参数文件方式 ...

  5. 【dubbo】dubbo-admin在jdk 1.8上部署出错问题

    今天在linux上部署dubbo-admin-2.5.4,一直报错: ERROR context.ContextLoader - Context initialization failedorg.sp ...

  6. SQL中的CASE的用法

    CASE在SQL语句中,很有点类似java等高级编程语言中的switch这样子的多分枝语句,但是有点不同的是,case后面接的是when,另外,when的后续分枝有点类似if后面接else.这个是我的 ...

  7. C/C++中产生随机数(rand,srand用法)

    计算机的随机数都是由伪随机数,即是由小M多项式序列生成的,其中产生每个小序列都有一个初始值,即随机种子.(注意: 小M多项式序列的周期是65535,即每次利用一个随机种子生成的随机数的周期是65535 ...

  8. asp.net mvc 页面传值的方法总结

    转自:http://msprogrammer.serviciipeweb.ro/2012/01/15/usual-methods-to-transfer-data-from-page-to-page- ...

  9. MySQL时间戳和时间格式转换函数

    MySQL时间戳和时间格式转换函数:unix_timestamp and from_unixtime unix_timestamp将时间转化成时间戳格式.from_unixtime将时间戳转化成时间格 ...

  10. 【Linux】之系统工具top

    top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.下面详细介绍它的使用方法.top是一个动态显示过程,即可以通过用户按键来不断刷新 ...