#C5012. Chemical Formula Reduction
Chemical Formula Reduction
Chemical Formula Reduction
You are given a string representing a chemical formula. The formula is composed of lowercase letters where each letter represents a chemical element. In this problem, your task is to reduce the chemical formula by removing any consecutive duplicate letters. For example, if the input formula is aabbcc
, the output should be abc
, because you only need one occurrence of each group of consecutive identical elements.
Note: If the formula is empty, output an empty string. The order of the characters in the original formula is maintained in the reduced formula.
Example:
- Input: aabbcc → Output: abc
- Input: abcdef → Output: abcdef
- Input: aavvbbvv → Output: avbv
inputFormat
The input is read from standard input and consists of:
- The first line contains an integer T representing the number of test cases.
- The following T lines each contains a string representing a chemical formula.
outputFormat
For each test case, output the reduced chemical formula on a new line to the standard output.
## sample3
aabbcc
abcdef
aavvbbvv
abc
abcdef
avbv
</p>