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个个数在 ...
随机推荐
- 详尽介绍FireFox about:config
一.什么是about:config about: config: 是Firefox的设置页面,Firefox提供了不少高级设置选项在这里以便让你可以更加详细地控制Firefox的运行方式.官方不推荐 ...
- jQuery Mobile_表单元素
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- eclipse svn subclipse下载地址
http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=2240 Eclipse 3.x Subclipse release ...
- DMALL刘江峰:生鲜市场具有巨大O2O改造空间
今日,全球移动互联网大会(GMIC)在北京-国家会议中心开幕.DMALL创始人刘江峰在全球O2O峰会论坛作主题发言时谈到,生鲜市场具有巨大O2O改造空间.同时这也是刘江峰在离开荣耀之后首次登台介绍自己 ...
- DataList与Repeater嵌套绑定
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="home.aspx.cs&quo ...
- MongoDB shell 格式化
直接的方法: db.collection.find().pretty(); 如果想要所有的查询都格式化,可以执行: echo "DBQuery.prototype._prettyShell ...
- Node.js 相关资料网站汇总
地址:https://cnodejs.org/ nodejs中文网:http://nodejs.cn/ nodejs中文网:http://www.nodejs.net/ 相关API地址:http:// ...
- 黄聪:wordpress/wp-admin目录文件
wp-admin/admin.php:管理文件的核心文件.用来连接数据库,整合动态菜单数据,显示非核心控制页面等. wp-admin/admin-db.php wp-admin/admin-foote ...
- 黄聪:wordpress如何获取当前页面的URL
一行代码搞定 <? echo home_url( add_query_arg( array() ) ); ?>
- *.hbm.xml讲解
<!-- package声明pojo类所在的包,如果不写 那么在class中需要指明pojo类所在的包 schema指数据库模式 一个模式下可以有多张表 --> <hibernate ...