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<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<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<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<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<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<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<LEN1;++J) str2[k++]=Str1[j]; STR2[K]=' /'; strcpy (STR1,STR2); if(POS+LENCP>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: )