NABILHACKER - Hack the Password

Credit:

  • Problem Set and Data set: Yasir Uddin Ahamed (Nabil)
  • Alternate Solution: Iqbal Hossain Bappy

Many people asked me what actually contest programming do in real life projects. That does not feel so interesting to me. What I found interesting is, one day a hacker friend came to me. He asked me to solve one of his hacking problems.

When you try to steal someone's password, you may set a keylogger in his/her computer. Keylogger will give you a string that is typed as the password. But there is a problem, it will give you everything victim typed such as left key, right key, backspace everything. (Left key and right key means the keys you use to play car games, and backspace is the key you use to remove a letter, the button on the top of "Enter" button. )

Suppose, the victim typed "generio312" as password, but he follows these criteria:

  1. he typed generio1.
  2. Then he pressed the left key, and press 3. So the password will be generio31.
  3. Then he pressed the right key and press 2. So the password will be generio312.
  4. Now he typed ghj and then press backspace three times and remove these three letters. So the final password is generio312.

But, as I said, keylogger gives you all the typed key. You will get "generio1<3>2ghj---". (Here, < for left key, > for right key and - for backspace.)

Input

At first input T, the number of test cases.

Then input T strings. 1<=|s|<=10^6. The strings will include uppercase, lowercase, <, >, - and digits 0 - 9.

Output

The output should contain a string each line, the password.

Example

Input:

2 BP<A>Cd- ThisIsS3Cr3t Output: BAPC ThisIsS3Cr3t


Added by:Nabil
Date:2018-09-27
Time limit:2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All

hide comments
2023-08-26 03:40:48 Rafail Loizou
The sample output is incorrect it should have been:

C
ThisIsS3Cr3t

So implement the code as the instruction says and you will get the AC.

Last edit: 2023-08-26 03:40:59
2020-09-22 19:44:58
Solved using linked list;)
2019-12-05 03:27:32
Just choose appropriate DS ......
2018-12-21 02:46:18 Boopathi Rajaa
I'm using Go and TLE for O(n).
2018-10-03 10:01:33
i love stack <3
2018-10-02 21:12:53
@kaushalag29 O I found your solution. insert and erase in vectors take O(n) complexity, so your complexity is technically O(n^2) (I assume). Instead of insert and delete, please try to use push_back and pop_back.
2018-10-02 20:59:36
@kaushalag29 Which one is your solution? O(n) must get AC.
2018-10-02 20:54:27
@lolipop98 Yes.
2018-09-29 12:09:45
Do we assume that ">>" (right key) at the START of an expression are redundant as in most textfields these days??
2018-09-29 11:07:12
@Nabil: O(n) gives TLE?What is the expected time complexity?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.