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个个数在 ...
随机推荐
- html之filedset标签
fieldset 元素可将表单内的相关元素分组,当一组表单元素放到 <fieldset> 标签内时,浏览器会以特殊方式来显示它们,它们可能有特殊的边界.3D 效果,或者甚至可创建一个子表单 ...
- Amoeba:开源的分布式数据库Porxy解决方案
http://www.biaodianfu.com/amoeba.html 什么是Amoeba? Amoeba(变形虫)项目,该开源框架于2008年 开始发布一款 Amoeba for Mysql软件 ...
- 无状态Web应用集成——《跟我学Shiro》
http://www.tuicool.com/articles/iu2qEf 在一些环境中,可能需要把Web应用做成无状态的,即服务器端无状态,就是说服务器端不会存储像会话这种东西,而是每次请求时带上 ...
- rsync配置中的auth error,一个隐秘的错误
我们都知道rsync是linux自带的功能强大的文件同步协议. 为了做免密码文件同步,所以,有多种配置.但是种种配置中,可能会遇到一个让人很纠结的问题,那就是安全认证错误的问题! 这个配置,是基于rs ...
- IOS开发-UIBarButtonItem系统自带图标总结
1.这四个返回的是后面的单词. UIBarButtonSystemItemDone UIBarButtonSystemItemCancel UIBarButtonSystemItemEdit UIBa ...
- 一个平时写程序通用的Makefile样例
//需要目标名和程序名字相同 .PHONY:clean all //伪目标 CC=gcc CFLAGS=-Wall -g BIN= //目标 all:$(BIN) %.o:%.c $(CC) $(CF ...
- html5外包—长年承接html5外包业务:《Sencha Touch权威指南》下载
<Sencha Touch权威指南>内容简介:如何才能全面而透彻地理解和掌握移动应用开发框架Sencha Touch并开发出令人心动的移动应用?<Sencha Touch权威指南&g ...
- 【linux磁盘分区--格式化】fdisk,parted,mkfs.ext3
磁盘分区完成后,一般就需要对分区进行格式化 磁盘分区命令主要有两个: fdisk :最大支持不超过2T分区: parted :支持GPT,适用于大容量分区: 分区指令的选择: 在RHEL系统上,用fd ...
- MVC 模型
dbcontent var ALLALBUMS=from album in db.albums orderby album.title ascending select album; storeman ...
- ADF_Database Develop系列3_通过UML进行数据库开发之将Database Diagram转为Class Diagram
2013-05-01 Created By BaoXinjian