2015北京网络赛 Mission Impossible (模拟题)

#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


#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#define LL long long
using namespace std;
const int MAXN = 10000 + 10;
int state, pos, cop;
char op[MAXN];
char s[MAXN];
char clip[MAXN];
int main()
{
    int T;
    int M;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%d%s", &M, s);
        int len = strlen(s);
        pos = 0;//guang biao wei zhi
        state = 0; // insert mode
        cop = 0; // nothing;
        int n = 0;
        int cpoypositon = -1;
        memset(op, '\0', sizeof(op));
        memset(clip, '\0', sizeof(clip));
        for(int i=0; i<len; i++)
        {
            if(s[i] >= 'a' && s[i] <= 'z')
            {
                    if(state)
                    {
                        if(pos >= M) continue;
                        op[pos++] = s[i];
                    }
                    else
                    {
                        int ll = strlen(op);
                        if(ll >= M) continue;
                        for(int k=ll; k>pos; k--)
                            op[k] = op[k-1];
                        op[pos++] = s[i];
                    }
                cop = 0;
            }
            else if(s[i] >= 'A' && s[i] <= 'Z')
            {
                if(s[i] == 'L')
                {
                    pos--;
                    pos = max(0, pos);
                }
                else if(s[i] == 'R')
                {
                    pos++;
                    int ll = strlen(op);
                    pos = min(ll, pos);
                }
                else if(s[i] == 'S')
                {
                    state = 1 - state;
                    cop = 0;
                }
                else if(s[i] == 'D')
                {
                    int ll = strlen(op);
                    if(cop == 0 && pos < ll)
                    {
                        op[pos] = '\0';
                        for(int k=pos + 1;k<ll;k++)
                            op[k-1] = op[k];
                        op[ll-1] = '\0';
                    }
                    else if(cop == 1&& pos < cpoypositon)
                    {
                        for(int k=pos; k<cpoypositon; k++)
                            op[k] = '\0';
                        int c = pos;
                        for(int k=cpoypositon; k<ll; k++)
                            op[c++] = op[k];
                        for(int k=c; k<ll; k++) op[k] = '\0';
                    }
                    else if(cop == 1 && pos > cpoypositon)
                    {
                         for(int k=cpoypositon; k<pos; k++)
                            op[k] = '\0';
                         int c = cpoypositon;
                         for(int k=pos; k<ll; k++)
                            op[c++] = op[k];
                         for(int k=c; k<ll; k++) op[k] = '\0';
                         pos = cpoypositon;
                    }
                    cop = 0;
                }
                else if(s[i] == 'B')
                {
                    if(pos > 0)
                    {
                        int ll = strlen(op);
                        s[pos-1] = '\0';
                        for(int k=pos-1; k<ll-1; k++)
                        {
                            op[k] = op[k+1];
                        }
                        op[ll-1] = '\0';
                        pos--;
                    }
                    cop = 0;
                }
                else if(s[i] == 'C')
                {

                    cop = 1 - cop;
                    if(cop == 1)
                    {
                        cpoypositon = pos;
                    }
                    else
                    {
                        memset(clip, '\0', sizeof(clip));
                        if(cpoypositon < pos)
                        {
                            int c = 0;
                            for(int k=cpoypositon; k<pos; k++)
                                clip[c++] = op[k];
                        }
                        else if(pos < cpoypositon)
                        {
                            int c = 0;
                            for(int k=pos; k<cpoypositon; k++)
                                clip[c++] = op[k];
                        }
                    }
                }
                else if(s[i] == 'V')
                {
                    if(state)
                    {
                        int l = strlen(clip);
                        if(pos + l > M) continue;
                        for(int k=pos; k<pos+l; k++)
                        {
                            op[k] = clip[k-pos];
                        }
                        pos = pos + l;
                    }
                    else
                    {
                        int l = strlen(clip);
                        int ll = strlen(op);
                        if(ll + l > M) continue;
                        for(int k=ll-1; k>=pos; k--)
                        {
                            op[k + l] = op[k];
                        }
                        for(int k=pos; k<pos + l; k++)
                        {
                            op[k] = clip[k - pos];
                        }
                        pos = pos + l;
                    }
                    cop = 0;
                }
            }
        }
        if(strlen(op) == 0) printf("NOTHING\n");
        else printf("%s\n", op);
    }
    return 0;
}
/*
100
100 abcdeLCLLD
5 abcLkjff
15 abcBBdeLLDDxzDDDDRRRR
25 abcdefgLLLSxyzSLLku
20 abcdefgLLCkLLCRRRRRCLV
20 abcdefgLLCkLLCRRRRCLLLSV
30 abcdeCLLCRRVCLRCabVkz
10 abcBBBLB
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值