CF1626A Equidistant Letters
题目描述
给定一个字符串 $s$,由小写字母组成。每个字母在字符串中出现不超过两次。
您的任务是重新排列字符串中的字母,使每对相同字母之间的的距离相等。不允许添加或删除字母。
可以证明答案总是存在的。如果有多个答案,请打印其中任何一个。
输入格式
第一行包含一个整数 $t$ $(1\le t\le 10^3,1 \le T \le 10)$,为测试用例的数量。
每个测试用例由一个非空字符串 $s$ 组成,由小写拉丁字母组成。每个字母在字符串中出现的次数不超过两次。字符串的长度不超过52。
输出格式
对于每个测试用例,打印一个字符串。每个字母在其中出现的次数应与在字符串 $s$ 中出现的次数相同。对于恰好出现两次的每一对字母,该对字母之间的距离应全部相同。
如果有多个答案,请打印其中任何一个。
说明/提示
In the first testcase of the example, the only letter that appears exactly twice is letter 'l'. You can rearrange the letters arbitrarily, since there are no distances to compare.
In the second testcase of the example, the letters that appear exactly twice are 'a', 'b' and 'c'. Initially, letters 'a' are distance $ 6 $ apart, letters 'b' are distance $ 4 $ apart and letters 'c' are distance $ 2 $ apart. They are not the same, so we have to rearrange the letters. After rearrangement, letters 'a' are distance $ 2 $ apart, letters 'b' are distance $ 2 $ apart and letters 'c' are distance $ 2 $ apart. They are all the same, so the answer is valid.
In the third testcase of the example, there are no letters that appear exactly twice. Thus, any rearrangement is valid. Including not changing the string at all.