Hiho Mission Impossible 6 (impersonation not submitted for validation: )

Source: Internet
Author: User

Test instructions: Analog text manipulation

Idea: Simulation

#include <iostream>#include<stdio.h>#include<string.h>using namespacestd;#defineMAXN 10005intM;CharCMD[MAXN];CharSTR1[MAXN],STR2[MAXN];CharCOPYSTR[MAXN];voidf () {intI,J,K,LEN,LEN1,LEN2,LENCP; Len=strlen (CMD);//command LengthLen1=len2=0;//Text Lengthlencp=0;//Clipboard length    intpos=0;//cursor Position    intMode=0;//0 "Insert mode", 1 "Overwrite mode "    intCopystate=0;//0 "Nothing", 1 "START"    intCopyposition1,copyposition2;  for(i=0; i<len;++i) {        if(cmd[i]>='a'&&cmd[i]<='Z'){            if(copystate==1) copystate=0; if(len1<M) {                if(pos==len1) {Str1[len1++]=Cmd[i]; STR1[LEN1]=' /'; ++POS; }                Else{                    if(mode==0){                         for(j=k=0; j<pos;++j) str2[k++]=Str1[j]; Str2[k++]=Cmd[i];  for(J=POS;J&LT;LEN1;++J) str2[k++]=Str1[j]; STR2[K]=' /';                        strcpy (STR1,STR2); ++len1; ++POS; //cout<<len1<<endl; //cout<<str1[0]<<endl;                    }                    Else{                         for(j=k=0; j<pos;++j) str2[k++]=Str1[j]; Str2[k++]=Cmd[i];  for(j=pos+1; j<len1;++j) str2[k++]=Str1[j]; STR2[K]=' /';                        strcpy (STR1,STR2); ++POS; }                }            }        }        Else if(cmd[i]=='L'){            if(pos>0)--POS; }        Else if(cmd[i]=='R'){            if(POS&LT;LEN1) + +POS; }        Else if(cmd[i]=='S'){            if(copystate==1) copystate=0; if(mode==0) mode=1;//becomes overridden            ElseMode=0;//becomes inserted        }        Else if(cmd[i]=='D'){            if(copystate==1) {copystate=0; CopyPosition2=POS; if(copyposition1<CopyPosition2) {                     for(j=k=0; j<copyposition1;++j) str2[k++]=Str1[j];  for(J=COPYPOSITION2;J&LT;LEN1;++J) str2[k++]=Str1[j]; Str2[k++]=' /';                    strcpy (STR1,STR2); Len1=len1-(copyposition2-copyPosition1); }                Else{                     for(j=k=0; j<copyposition2;++j) str2[k++]=Str1[j];  for(J=COPYPOSITION1;J&LT;LEN1;++J) str2[k++]=Str1[j]; STR2[K]=' /';                    strcpy (STR1,STR2); Len1=len1-(copyposition1-copyPosition2); }            }            Else{                if(pos<len1) {                     for(j=k=0; j<pos;++j) str2[k++]=Str1[j];  for(j=pos+1; j<len1;++j) str2[k++]=Str1[j]; STR2[K]=' /';                    strcpy (STR1,STR2); --len1; }            }        }        Else if(cmd[i]=='B'){            if(copystate==1) copystate=0; if(pos>0){                 for(j=k=0; j<pos-1; ++j) str2[k++]=Str1[j];  for(J=POS;J&LT;LEN1;++J) str2[k++]=Str1[j]; STR2[K]=' /';                strcpy (STR1,STR2); --len1; --POS; }        }        Else if(cmd[i]=='C'){            if(copystate==0) {copystate=1; CopyPosition1=POS; }            Else{copystate=0; CopyPosition2=POS; if(copyposition1!=CopyPosition2) {                    if(copyposition1<CopyPosition2) {                         for(j=copyposition1,k=0; j<copyposition2;++j) Copystr[k++]=Str1[j]; COPYSTR[K]=' /'; LENCP=copyposition2-CopyPosition1; }                    Else{                         for(j=copyposition2,k=0; j<copyposition1;++j) Copystr[k++]=Str1[j]; COPYSTR[K]=' /'; LENCP=copyposition1-CopyPosition2; }                }                Else{memset (copystr,' /',sizeof(COPYSTR)); LENCP=0; }            }        }        Else if(cmd[i]=='V'){            if(lencp>0){                if(mode==0){                    if(len1+lencp<=M) {                         for(j=k=0; j<pos;++j) str2[k++]=Str1[j];  for(j=0; j<lencp;++j) str2[k++]=Copystr[j];  for(J=POS;J&LT;LEN1;++J) str2[k++]=Str1[j]; STR2[K]=' /';                        strcpy (STR1,STR2); Len1=len1+LENCP; POS=pos+LENCP; }                }                Else{                    if(pos+lencp<=l) {                         for(j=k=0; j<pos;++j) str2[k++]=Str1[j];  for(j=0; j<lencp;++j) str2[k++]=Copystr[j];  for(J=POS+LENCP;J&LT;LEN1;++J) str2[k++]=Str1[j]; STR2[K]=' /';                        strcpy (STR1,STR2); if(POS+LENCP&GT;LEN1) len1=pos+LENCP; POS=pos+LENCP; }                }            }        }    }}intMain () {intT; scanf ("%d",&T);  while(t--) {scanf ("%d",&l); //m=100;scanf"%s", CMD);        f (); if(str1[0]) printf ("%s\n", STR1); Elseprintf"nothing\n"); }    return 0;}
View Code

Hiho Mission Impossible 6 (impersonation not submitted for validation: )

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.