2015 ACM/ICPC Asia Regional Beijing Online
- 样例输入
-
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;
}
描述
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".
2015 ACM/ICPC Asia Regional Beijing Online的更多相关文章
- 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 ...
- (并查集)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 ...
- (二叉树)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) ...
- 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 ...
- 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 ...
- 【二分】【最长上升子序列】HDU 5489 Removed Interval (2015 ACM/ICPC Asia Regional Hefei Online)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5489 题目大意: 一个N(N<=100000)个数的序列,要从中去掉相邻的L个数(去掉整个区间 ...
- 【线段树】HDU 5493 Queue (2015 ACM/ICPC Asia Regional Hefei Online)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5493 题目大意: N个人,每个人有一个唯一的高度h,还有一个排名r,表示它前面或后面比它高的人的个数 ...
- 【动态规划】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+ ...
- 【贪心】【模拟】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个个数在 ...
随机推荐
- [Android设计模式]Android退出应用程序终极方法
如何干净彻底地退出Android应用程序,是很多开发者的心头痒.如何干净地关闭所有已打开的Activity? 如何关闭指定的Activity? 如何关闭一类Activity? 这里,我们提出一种通过实 ...
- SQL Server 2005 分区表创建实例
--创建一个分区函数(默认为左边界)CREATE PARTITION FUNCTION PARTFUNC1(INT)AS RANGEFOR VALUES(1000,2000,3000,4000,500 ...
- BI案例:KPI在商业智能中的应用(ZT)
KPI(Key Performance Indication)即关键业绩指标,是通过对组织内部某一流程的输入端.输出端的关键参数进行设置.取样.计算.分析,衡量流程绩效的一种目标式量化管理指标,是把企 ...
- mootools里选择器$,$$,$E,$ES等的区别
区别就是 $和$$都是1个参数, $适用于ID,或者ID代表的对象 $$适用于CSS选择器 $E和$ES,有2个参数,第二个参数是可选参数代表(filter,即某个ID范围里的元素) $E('inpu ...
- Discuz!NT 3.9.913 Beta DIY过程
前提: 论坛的源码版本为dnt_3.9.913_sqlserver_beta.zip,以下例子都以这个版本为原型修改 dnt_3.9.913数据字典:下载 目前(2013年10月21日)官网的asp. ...
- 【转】关于 hashCode() 你需要了解的 3 件事
在 Java 中,每一个对象都有一个容易理解但是仍然有时候被遗忘或者被误用的 hashCode 方法.这里有3件事情要时刻牢记以避免常见的陷阱. 一个对象的哈希码允许算法和数据结构将对象放入隔间,就象 ...
- android打印调用栈
在某些机器上,不能下断点,出现了某个诡异的问题,想到唯一的解决方式,就是打印调用栈了,google发现这个,记录下,以后备用 Log.d(",Log.getStackTraceString( ...
- Eclipse无法进入Debug模式
转载自:http://blog.sina.com.cn/s/blog_4b3191950100v8h5.html 原因:多半是因为程序根本就没运行到断点处,所以重新检查自己设置的断点.
- VisualSVN Server以及TortoiseSVN客户端的配置和使用方法
http://www.cnblogs.com/beautifulFuture/archive/2014/07/01/3818211.html 近期学习代码管理工具,首先学习一下svn和Tortoise ...
- 二. log4j配置文件
log4j的配置文件 # Output pattern : date [thread] priority category - message log4j.rootLogger=info,Consol ...