| Problem ID | 1061 | |||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Title | Tribute (Editor) | |||||||||||||||||||||||||||||||||||||||
| Description | This problem is not about the greatest editor in the world; it is just a tribute. The Tenacious eDitor is an attempt to clone to power of a certain modal editor. However, it is notoriously bug-ridden. You've been asked to replace Kyle (who quit the devteam) and help with fixing some of the bugs. The main problem with the current release of td, as it is commonly referred to, is that it cannot differentiate between text on a line and commands. Whenever a user wants to type an x, the editor interprets it as a command to delete the last character. This is problematic. Thankfully, commands are case-sensitive, and each letter is at most a single command (sometimes uppercase, sometimes lowercase), so one can manage to write any given line of text as long as it's allowed to look like something written by a fourteen-year-old hacker wannabe. Editing occurs in an edit buffer, which starts out empty. The cursor in td rests in gaps, locations surrounding each printed character. When a non-command character is entered, the character is inserted to the right of the cursor's current location and the cursor moves to the gap to the right of the new character. (This is the standard behavior of most editors.) A line with no characters has a single gap. A line with a single printable character has two (one before and one after), a line with two printable characters has three, and so on. The currently-implemented commands are:
For the purposes of this problem, the only characters are uppercase and lowercase characters, digits, and spaces. When a character is added internally to a line of text, all subsequent characters shift to the right (as in "insert mode"); when characters are deleted from anywhere other than the end of a line, all subsequent characters shift to the left. Any commands which cannot properly do anything (attempting to move past the first or last gap, deleting characters when none exist, and so on) do nothing. They do not show up as printed characters. Each line represents a different session of td; at the beginning of a new session, the edit buffer is empty. Given a series of keystrokes by a user, can you determine what text actually results if it were entered in the current version of td? | |||||||||||||||||||||||||||||||||||||||
| Input | Input to this problem will begin with a line containing a single integer N (1 ≤ N ≤ 100) indicating the number of data sets. Each data set consists of a single line of characters, as defined above, with no leading or trailing whitespace. There are no less than 1 and no more than 100 characters per line. They represent the series of keystrokes entered by a user for a particular session of td. | |||||||||||||||||||||||||||||||||||||||
| Output | For each data set, print the final state of the edit buffer from the sequence of characters entered, with a carat (^) at the location of the cursor. | |||||||||||||||||||||||||||||||||||||||
| Sample Input | 2 Deletex bigdeleteKduPc bigduPD esreverR midinhhdleGxx midelletehhhxGfmoo THis ratHer obnoXious line oF CHaraCters surPrisingly triggers no Commands | |||||||||||||||||||||||||||||||||||||||
| Sample Output | moo^elet duPP bigduPbigduP reverse middle midelete THis ratHer obnoXious line oF CHaraCters surPrisingly triggers no Commands^ | |||||||||||||||||||||||||||||||||||||||
| Hint | ||||||||||||||||||||||||||||||||||||||||
| Last Modified | 2012-04-23 13:47:35 | |||||||||||||||||||||||||||||||||||||||
| Time Limit | 1 seconds | |||||||||||||||||||||||||||||||||||||||
| Memory Limit | 128 MB | |||||||||||||||||||||||||||||||||||||||
| Accepted Solutions | 1 | |||||||||||||||||||||||||||||||||||||||
| Submitted Solutions | 1 | |||||||||||||||||||||||||||||||||||||||
| Difficulty Factor | 1028 | |||||||||||||||||||||||||||||||||||||||
Facebook