#P1038. 字符串重排 (String Reorder)
字符串重排 (String Reorder)
Source: CSES Problem Set (Task 1743)
Link: https://cses.fi/problemset/task/1743
Category: Introductory Problems
- Time limit: 1.00 s
- Memory limit: 512 MB
Your task is to reorder the characters of a string so that no two adjacent characters are the same. What is the lexicographically minimal such string?
Input
The only line has a string of length consisting of characters A–Z.
Output
Print the lexicographically minimal reordered string where no two adjacent characters are the same. If it is not possible to create such a string, print .
Constraints
Example
Input:
HATTIVATTI
Output:
AHATITITVT