Decode the message from the given key logger. The logger consists: '-' representing backspace:the character directly before the cursor position is deleted, if there is Any. ' < ' (and ' > ') representing the left (right) arrow:the cursor is moved 1 character to the left (right), if possible. alphanumeric characters, which is part of the password, unless deleted later. Here assumes ' insert mode ': If the cursor isn't at the end of the line, and you type a alphanumeric character, then all Characters after the cursor move one position to the right.InputThe first line contains a single integer T, indicating the number of test cases.
Each test case is contains a string L, with 1 <= Length (L) <= 1000000.
OutputFor each test case, output the case number first, and then the decoded message string in a line.Sample Input2
<<o<il>>>veu-
Helloacmer
Sample OutputCase 1:ilove
Case 2:helloacmer
Test instructions:< represents the cursor to the left,> represents the right shift of the cursor,-represents the deletion of the previous element, requires the output of all the remaining string ideas: The first direct simulation, timed out, and then Baidu a bit, how to insert elements in the middle of the list, so learned a bit about the use of iterators, It's really pretty easy to do this with an iterator.
#include <stdio.h> #include <string.h> #include <list> #include <algorithm> using namespace std;
Char s1[1000005];
List<char> L;
List<char>::iterator lpos;//iterator int len1;
int main () {int n,cas = 1,i,j;
int Biao;
scanf ("%d", &n);
while (n--) {l.clear ();
scanf ("%s", S1);
Biao = 0;
printf ("Case%d:", cas++);
if (!strstr (S1, "<") &&!strstr (S1, ">") &&!strstr (S1, "-")) {printf ("%s\n", S1);
Continue
} len1 = strlen (S1);
Lpos = L.end ();//iterators point to the end of the list for (i = 0; i<len1; i++) {if (s1[i] = = < ') { if (Lpos!=l.begin ())//iterator not to head lpos--;//left, iterator left} else if (s1[i] = = ' > ') {if (Lpos!=l.end ())//Not to end lpos++;//right} els
E if (s1[i] = = '-')//delete { if (lpos! = L.begin ())) lpos=l.erase (--lpos);//iterators move forward and delete the elements referred to by iterators} else L.insert (lpos,s1[i]);//add Element} for (Lpos = L.begin () at the point where the iterator refers; Lpos!=l.end ();
lpos++)//iterator by the list beginning to the end of printf ("%c", *lpos);
printf ("\ n");
} return 0;
}