#1228 : Mission Impossible 6

时间限制: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 题意:比较复杂,建议看英文,大致是要写一个文本编辑器,像记事本一样的东西
题解:虽说看上去模拟好像过不了,然而模拟是可以过得,然而我这个大渣渣搞了两小时都没有AC,连累队友了TAT
可以用链表模拟也可以用数组模拟
给一下我的WA的代码吧。。。
 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name) {
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} const int N = , M = ;
struct CHAR {
char ch;
int Pre, Nex;
} Arr[M];
int Tot, Pos, Len;
int n;
// Mode : 0 -> insert 1 -> Cover
int WorkLength;
char Data[N];
int Mode, CopyPos, CopyLength;
char Clipboard[N]; inline void Solve(); inline void Input() {
int TestNumber;
scanf("%d", &TestNumber);
while(TestNumber--) {
scanf("%d", &n);
scanf("%s", Data+);
WorkLength = strlen(Data+);
Solve();
}
} inline void Insert(char x) {
if(Mode == ) {
// Insert
if(Len+ > n) return;
Tot++;
Arr[Tot].ch = x;
Arr[Tot].Pre = Pos, Arr[Tot].Nex = Arr[Pos].Nex;
int t = Arr[Pos].Nex;
Arr[t].Pre = Tot, Arr[Pos].Nex = Tot;
Pos = Tot;
Len++;
} else {
// Cover
if(Arr[Pos].Nex == -) return;
Pos = Arr[Pos].Nex;
Arr[Pos].ch = x;
}
} inline void LeftMove() {
if(Arr[Pos].Pre == -) return;
Pos = Arr[Pos].Pre;
} inline void RightMove() {
if(Arr[Pos].Nex == -) return;
Pos = Arr[Pos].Nex;
} inline void DeleteNext() {
if(Arr[Pos].Nex == -) return;
int t = Arr[Pos].Nex;
Arr[Pos].Nex = Arr[t].Nex;
if(Arr[t].Nex != -) Arr[Arr[t].Nex].Pre = Pos;
Len--;
} inline void DeleteThis() {
if(Pos <= ) return;
int x = Arr[Pos].Pre, y = Arr[Pos].Nex;
if(x != ) Arr[x].Nex = y;
if(y != ) Arr[y].Pre = x;
Pos = x;
Len--;
} inline int FindPos() {
int Cnt = ;
for(int x = ; x != Pos; x = Arr[x].Nex) Cnt++;
return Cnt;
} inline int FindPos(int Num) {
int x = ;
For(i, , Num) x = Arr[x].Nex;
return x;
} inline void CopyWork() {
if(CopyPos == -) CopyPos = FindPos();
else {
int x = CopyPos, y = FindPos();
CopyPos = -;
if(x < y) {
x = FindPos(x);
y = Pos;
} else {
y = FindPos(x);
x = Pos;
}
CopyLength = ;
while(x != y) {
x = Arr[x].Nex;
Clipboard[++CopyLength] = Arr[x].ch;
}
}
} inline void Delete() {
int x = CopyPos, y = FindPos();
CopyPos = -;
Len -= max(x, y)-min(x, y);
if(x < y) {
x = FindPos(x);
y = Pos;
} else {
y = FindPos(x);
x = Pos;
}
Arr[x].Nex = Arr[y].Nex;
if(Arr[y].Nex != -) Arr[Arr[y].Nex].Pre = x; } inline void Paste() {
if(Len+CopyLength > n) return;
For(i, , CopyLength) Insert(Clipboard[i]);
if(Mode == ) Len += CopyLength;
} inline void Solve() {
CopyPos = -;
Arr[].Pre = Arr[].Nex = -, Tot = Len = , Pos = ;
Mode = , CopyLength = ;
clr(Clipboard, ); For(i, , WorkLength) {
char x = Data[i]; if(CopyPos != - && x != 'L' && x != 'R' && x != 'D' && x != 'C') CopyPos = -; if(x >= 'a' && x <= 'z') Insert(x);
else if(x == 'L') LeftMove();
else if(x == 'R') RightMove();
else if(x == 'S') Mode ^= ;
else if(x == 'D') {
if(CopyPos != -) Delete();
else DeleteNext();
} else if(x == 'B') DeleteThis();
else if(x == 'C') CopyWork();
else if(x == 'V') Paste();
} if(Len > ) {
int x = Arr[].Nex;
while(x != -) {
printf("%c", Arr[x].ch);
x = Arr[x].Nex;
}
puts("");
} else puts("NOTHING");
} int main() {
#ifndef ONLINE_JUDGE
SetIO("B");
#endif
Input();
//Solve();
return ;
}

ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 B Mission Impossible 6的更多相关文章

  1. ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 Scores

    #1236 : Scores 时间限制:4000ms 单点时限:4000ms 内存限制:256MB 描述 Kyle is a student of Programming Monkey Element ...

  2. ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛

    #1235 : New Teaching Buildings 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 Thanks to the generous finance ...

  3. hihoCoder 1578 Visiting Peking University 【贪心】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1578 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for ...

  4. ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 A Simple Job

    描述 Institute of Computational Linguistics (ICL), Peking University is an interdisciplinary institute ...

  5. ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛 The Book List

    描述 The history of Peking University Library is as long as the history of Peking University. It was b ...

  6. hihoCoder 1389 Sewage Treatment 【二分+网络流+优化】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1389 : Sewage Treatment 时间限制:2000ms 单点时限:2000ms 内存限制:256MB 描述 After years of suffering, people coul ...

  7. hihoCoder 1391 Countries 【预处理+排序+堆】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1391 : Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, countr ...

  8. hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...

  9. ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum

    时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2^k-1. You need t ...

随机推荐

  1. nginx(四)初识nginx日志文件

    nginx 日志相关指令主要有两条,一条是log_format,用来设置日志格式,另外一条是access_log,用来指定日志文件的存放路径.格式和缓存大小,通俗的理解就是先用log_format来定 ...

  2. MySQL的分页

    有朋友问: MySQL的分页似乎一直是个问题,有什么优化方法吗?网上看到网上推荐了一些分页方法,但似乎不太可行,你能点评一下吗? 方法1: 直接使用数据库提供的SQL语句 ---语句样式: MySQL ...

  3. [官方教程] [ES4封装教程]1.使用 VMware Player 创建适合封装的虚拟机

    [转载处,http://bbs.itiankong.com/] 前言: 首先要明确的一点,系统封装操作的源计算机一般为虚拟计算机(简称虚拟机.VM等),这也是为什么我们要在封装教程的第一章就专门学习虚 ...

  4. Linux rsync 命令详解

    服务器之间常常要保持些文件或目录的一致,比如一些大的软件下载网站,它们通常使用多台服务器来提供下载服务.当一台服务器上的文件更新后,其它的服务器 也需要更新,而且 在更新的时候应该是只对新增或是修改过 ...

  5. 深入学习微框架:Spring Boot - NO

    http://blog.csdn.net/hengyunabc/article/details/50120001 Our primary goals are: Provide a radically ...

  6. Group Shifted Strings

    Given a string, we can "shift" each of its letter to its successive letter, for example: & ...

  7. Swap Two Nodes in Linked List

    Given a linked list and two values v1 and v2. Swap the two nodes in the linked list with values v1 a ...

  8. 在SharePoint 2010 母版页里添加自定义用户控件

    在SharePoint 2010 母版页里添加自定义用户控件(译) 使用自定义用户控件的好处: 1.容易部署:2.易于控制显示或隐藏. (在使用的过程中)可能要面对的问题是:如何在用户控件里使用Sha ...

  9. 如何破解excel宏的密码

    http://zhidao.baidu.com/question/140107193.html 最近下载了一个excel模板,使用excel宏编的,但实际需要需更改一下,但是他设置了工作表密码保护,谁 ...

  10. Mybatis if判断的坑

    具体情况参考这两篇文章: http://cheng-xinwei.iteye.com/blog/2008200 http://www.cnblogs.com/tv151579/p/3297691.ht ...