zoukankan      html  css  js  c++  java
  • 2015 ACM/ICPC Asia Regional Beijing Online

    时间限制: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


    题意:

    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
    ";
            cout<<str<<endl;
        }
        return 0;
    }
    


  • 相关阅读:
    poj3032
    poj2603
    poj2019
    poj2369
    AVI 录像功能压缩算法设置
    陆其明的新书《脚本驱动的应用软件开发方法与实践》
    c# 动态编译
    !!!分享:把bmp格式的图片转化为AVI格式的视频操作的封装类其中对于AVI API的函数的使用较为完整
    视频文件格式和视频编码方式
    activex 控件的id 定义位置+使用ocx控件的客户端程序中对控件定义的文件中控件id定义的位置
  • 原文地址:https://www.cnblogs.com/zswbky/p/5431916.html
Copyright © 2011-2022 走看看