-
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
描述
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".
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <list>
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int,int> P;
typedef long long LL;
const double eps=1e-9;
const int maxn=10000+10;
int m;
string s;
list<char> lt;
list<char>::iterator tmp,st,ed,pos;
char cpy[maxn];
int cpy_len;
int ifcpy;
int S;
int judge_num;
void show()
{
for(tmp=lt.begin(); tmp!=lt.end(); ++tmp)
{
printf("%c",*tmp);
}
puts("");
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
cin>>m>>s;
ifcpy = 0;
S = 0;
cpy_len = 0;
lt.clear();
pos=lt.begin();
for(int i=0; i<s.size(); i++)
{
if(s[i]=='S')
{
ifcpy = 0;
S = !S;
}
else if(s[i]>='a'&&s[i]<='z')
{
ifcpy = 0;
if(!S)
{
if(lt.size()>=m)continue;
lt.insert(pos , s[i]);
}
else if(S)
{
if(pos != lt.end())
lt.erase(pos++);
if(lt.size()>=m)continue ;
lt.insert(pos,s[i]);
}
}
else if(s[i]=='B')
{
ifcpy = 0;
if(pos != lt.begin())
{
pos--;
lt.erase(pos++);
}
}
else if(s[i]=='D')
{
if(!ifcpy)
{
if(pos != lt.end())
lt.erase(pos++);
}
else
{
if(judge_num>0)lt.erase(st,ed);
else if(judge_num<0)pos=lt.erase(ed,st);
}
ifcpy = 0;
}
else if(s[i]=='L'&&pos!=lt.begin())
{
pos--;
if(ifcpy)
{
ed = pos;
judge_num--;
}
}
else if(s[i]=='R'&&pos!=lt.end())
{
pos++;
if(ifcpy)
{
ed = pos;
judge_num++;
}
}
else if(s[i]=='C')
{
if(ifcpy==0)
{
ifcpy = 1;
st = ed = pos;
judge_num = 0;
}
else
{
ifcpy = 0;
cpy_len = 0;
if(judge_num==0)continue ;
if(judge_num>0)
{
for(tmp = st; tmp != ed; ++tmp)
{
cpy[cpy_len++] = *tmp;
}
}
else
{
for(tmp =ed; tmp != st; ++tmp)
{
cpy[cpy_len++] = *tmp;
}
}
}
}
else if(s[i] == 'V')
{
ifcpy = 0;
if(!S)
{
if(lt.size()+cpy_len>m)continue ;
for(int j=0; j<cpy_len; j++)
{
lt.insert(pos,cpy[j]);
}
}
else {
int len = 0;
for(tmp = lt.begin();tmp != lt.end()&&tmp != pos; ++tmp , len++)
if(len + cpy_len>m)continue;
for(int j=0; j<cpy_len; j++)
{
lt.insert(pos,cpy[j]);
if(pos != lt.end())
lt.erase(pos++);
}
}
}
}
if(!lt.size())puts("NOTHING");
else show();
}
return 0;
}