#abc242b. B - Minimize Ordering
B - Minimize Ordering
Score : points
问题描述
给定一个字符串 ,找出通过重新排列 的字符得到的字典序最小的字符串 。
这里,对于两个不同的字符串 和 ,若满足以下任一条件,则认为 在字典序上成立:
- 存在一个整数 ,使得 并且对于所有整数 ,都有 。
- 对于所有整数 ,有 ,并且 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a string . Find the lexicographically smallest string obtained by permuting the characters of .
Here, for different two strings and , holds lexicographically when one of the conditions below is satisfied.
- There is an integer such that and for all integers .
- for all integers , and .
Constraints
- is a string of length between and (inclusive) consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
Output
Print the lexicographically smallest string obtained by permuting the characters in .
Sample Input 1
aba
Sample Output 1
aab
Three strings can be obtained by permuting aba
:
aba
aab
baa
The lexicographically smallest among them is aab
.
Sample Input 2
zzzz
Sample Output 2
zzzz
update @ 2024/3/10 10:25:00