Title: On a computer without a monitor input a string, the keyboard is broken, will randomly appear home, and end button,
The string ' [' stands for the Home key (the first sentence), '] ' represents the end key (the end of the sentence) and asks the format of the last output string.
Analysis: Simulate screen operation, move cursor, simulate buffer output operation.
Description: The array simulates the list operation, follows the list operation, and visualizes the simulation.
1 //UVa11988 Broken Keyboard2 //Rujia Liu3#include <cstdio>4#include <cstring>5 Const intMAXN =100000+5;6 intLast, cur, next[maxn];//cursor is behind cur appended7 CharS[MAXN];8 9 intMain () {Ten while(SCANF ("%s", s+1) ==1) { One intn = strlen (s+1);//input saved in s[1], s[2] ... In Alast = cur =0; -next[0] =0; - the for(inti =1; I <= N; i++) { - CharCH =S[i]; - if(ch = ='[') cur =0; - Else if(ch = =']') cur =Last ; + Else { -Next[i] =Next[cur]; +Next[cur] =i; A if(cur = = last) last = i;//Update "Last character" number atcur = i;//Move Cursor - } - } - for(inti = next[0]; I! =0; i =Next[i]) -printf"%c", S[i]); -printf"\ n"); in } - return 0; to}
UVa 11988 array analog linked list