#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. FineUI第六天---表单控件

    表单控件 所有表单控件都有的属性有: ShowLabel:是否显示标签(默认值:true). ShowEmptyLabel:是否显示空白的标签(默认值:false). Label:标签文本(默认值:& ...

  2. ios中的category与extension

    http://blog.csdn.net/haishu_zheng/article/details/12873151   category和extension用来做类扩展的,可以对现有类扩展功能或者修 ...

  3. ZeroMQ之Push与Pull (Java)

    本系列文章均转自:http://blog.csdn.net/kobejayandy/article/details/20163431 在ZeroMQ中并没有绝对的服务端与客户端之分,所有的数据接收与发 ...

  4. Android ADB命令大全(通过ADB命令查看wifi密码、MAC地址、设备信息、操作文件、查看文件、日志信息、卸载、启动和安装APK等)

    ADB很强大,记住一些ADB命令有助于提高工作效率. 获取序列号: adb get-serialno 查看连接计算机的设备: adb devices 重启机器: adb reboot 重启到bootl ...

  5. 对比WDCP面板与AMH面板的区别与选择

    转载: http://www.laozuo.org/2760.html | 老左博客 随着VPS主机的性价比提高(其实就是降价)我们很多站长会越来越多的选择使用VPS搭建网站或者运营一些项目,相比较而 ...

  6. PHP很有用的一个函数ignore_user_abort ()

    PHP很有用的一个函数ignore_user_abort () 2013-01-16 14:21:31|  分类: PHP |  标签:php  函数  |举报|字号 订阅     ignore_us ...

  7. Smarty s01

    复习面向过程中,如何输出显示变量的内容 01.php 第一个版本,使用三个文件来输出html 1.访问文件 2.类MyTpl.class.php 3.一个html模板文件 课堂练习第一个版本 第二个版 ...

  8. Solr DIH导入出现 Data Config problem: 前言中不允许有内容 异常

    Solr配置DIH导入时出现 “Data Config problem: 前言中不允许有内容.” 异常. <response> <lst name="responseHea ...

  9. 【JAVA、C++】LeetCode 002 Add Two Numbers

    You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...

  10. codeforces B. Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/359/B 题目意思:给定n和k的值,需要构造一条长度为2n(每个元素取值范围只能是[1,2n])且元素各不 ...