← 返回 capitalone 的题目列表Arrange W, D, and L Results into Repeated WDL Groups
类型:online_judge
Given a string s consisting only of W, D, and L (win, draw, and loss), rearrange its characters as follows:
While at least one W, one D, and one L remain, append WDL to the result.
Once a complete WDL group can no longer be formed, append all remaining characters in W, then D, then L order.
Print the resulting string.
Input Format
One line containing string s.
Output Format
Print the rearranged string.
Constraints
1 <= len(s) <= 2 * 10^5
s[i] ∈ {'W', 'D', 'L'}
Example
Input:
WWWWLDDL
Output:
WDLWDLWW
Example
Input
WWWLLDDLD
Output
WDLWDLWDL