Problem copy too troublesome, throw a link
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18693
Direct simulation of the cursor operation time is more complex, so the list is stored in the order.
POS indicates the cursor position
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <algorithm>5#include <cmath>6 using namespacestd;7 Chars[200000];8 Charch;9 intLast,pos;//last store the position of the final character, POS stores the current cursor positionTen intnexto[200000]; One intMain () { A while(SCANF ("%s", s+1)!=EOF) { - intLen=strlen (s+1); -last=0;p os=0; thenexto[0]=0;//Initialize - inti; - for(i=1; i<=len;i++){ - if(s[i]=='[') pos=0; + Else if(s[i]==']') pos=Last ; - Else{ +nexto[i]=Nexto[pos]; Anexto[pos]=i; at if(Pos==last) last=i;//Update last Location -Pos=i;//Update cursor Position - } - } - for(i=nexto[0];i!=0; I=nexto[i]) printf ("%c", S[i]); -printf"\ n"); in } - return 0; to}
UVa 11988 Broken Keyboard (a.k.a. Beiju Text)