Back
Close

Deleting words and characters.

Statement

 Goal

We all make mistakes when typing. Computers provide us with the backspace key, represented as ^H, which simply deletes the last entered character.

But did you know that, in Unix terminals (like on Linux and macOS), you can also delete the last typed word using a single key combination? That key combination is Ctrl+W, represented as ^W. This lets do you delete text quicker than holding down the backspace key.

Exactly how ^W works varies from application to application, but for simplicity, we'll assume that when you press ^W, first it deletes all the trailing whitespace characters, and then it's going to delete the last typed word by deleting the last character until it finds a whitespace (or reached the beginning of a string).

Take in the keystrokes with ^H and ^W and return the resulting text.
Input
Line 1: A string containing the keystrokes with ^H and ^W.
Output
Line 1: The resulting text.
Constraints
Input string fits in a tweet (length is no longer than 280 characters).
Example
Input
Hello^H^H^H^Hi
Output
Hi

Game modes
Fastest, Shortest

Test cases
Hi Test
Input
Hello^H^H^H^Hi
Output
Hi

Validator 1 Validator
Input
hello^H^H^H^Hi
Output
hi

CodinGame Test
Input
Coding^HGame
Output
CodinGame

Validator 2 Validator
Input
Clash of c^HCode
Output
Clash of Code

Longer message Test
Input
Could^WWould you liek^H^Hke to solve a ^Wsome challenge?^Hs?
Output
Would you like to solve some challenges?

Validator 3 Validator
Input
Could^WWould you liek^H^Hke to solve a ^Wsome challenge?^Hs??
Output
Would you like to solve some challenges??

Hey ! Test
Input
Hey you^W!
Output
Hey !

Validator 4 Validator
Input
hey you^W!
Output
hey !

Hey! Test
Input
Hey you^W^H!
Output
Hey!

Validator 5 Validator
Input
hey you^W^H!
Output
hey!

Complicated Test
Input
This one is qui^^H^^^^Wpri^Het^h^H^Hty k^Hcomplicated.
Output
This one is pretty complicated.

Validator 6 Validator
Input
this one is qui^^H^^^^Wpri^Het^h^H^Hty k^Hcomplicated.
Output
this one is pretty complicated.

^_^ Test
Input
^W^H^W^HGreat job! ^_^
Output
Great job! ^_^

Validator 7 Validator
Input
^W^H^W^Hgreat job! ^_^
Output
great job! ^_^

Solution language

Solution

Stub generator input