AmazonOA #44
Get Encoded Name (Lex-Smallest Palindrome)
简单可在线判题
You are given a string letters that contains only lowercase letters and is itself a palindrome. Rearrange its characters and, among all rearrangements that are still palindromes, output the lexicographically smallest one.
输入格式
A single line containing the string letters. 1≤|letters|≤3×10^7; it contains only lowercase letters a-z, and letters is a palindrome.
输出格式
Output one line: the lexicographically smallest palindromic rearrangement.
样例 1
输入:
yxxy
输出:
xyyx
样例 2
输入:
cbabc
输出:
bcacb
样例 3
输入:
baab
输出:
abba
样例说明
Example 1: the characters of yxxy are two x and two y; the palindromic rearrangements are xyyx and yxxy, and the smaller one is xyyx. Example 2: in cbabc, a appears once and can only go in the center; the first half takes b and c, giving bcacb. Example 3: baab is rearranged into abba.