Given one line that consists of only letters, process as following:
- You maintain a string that's empty at the beginning.
- If the next input character is in the string, remove it from the string.
- If the next input character isn't in the string, append it to the string.
Output the final state of the string.
You can safely assume the input consists at least one character (i.e. non-empty), but there's no guarantee that the output isn't empty.
Pseudocode (Feel free to golf this):
str = EMPTY for each character ch in input if ch exists in str remove all ch from str else append ch to str print str
The input matches the regular expression
Sample test cases:
ABCDBCCBE -> ADCBE ABCXYZCABXAYZ -> A aAABBbAbbB -> aAbB GG -> (empty)
The input can be given in any applicable way, but it must be treated as a string, and the same for output. The program should not exit with an error.
The shortest program in each language wins!
Extra (Optional): Please explain how your program works. Thank you.