CF1156B.Ugly Pairs
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions (1,2) — "ab" and (2,3) — "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer T separate queries.
给你一个仅由小写拉丁字母组成的字符串。
如果字符串中一对相邻的字母在字母表中也相邻,则称这对字母为“丑陋的”。例如,字符串 "abaca" 在位置 (1,2)(即 "ab")和位置 (2,3)(即 "ba")处包含丑陋的字母对。注意:字母 'a' 和 'z' 在字母表中不视为相邻。
你能否重新排列给定字符串中的字母,使得其中不包含任何丑陋的字母对?你可以任意选择给定字符串中字母的排列顺序,但不能添加新字母,也不能删除已有字母。你也可以保持原有顺序不变。
如果存在多种可行方案,请输出任意一种即可。
此外,你还需要处理 T 个独立的查询。
输入格式
The first line contains a single integer T (1≤T≤100) — the number of queries.
Each of the next T lines contains string s (1≤∣s∣≤100) — the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set T=1.
第一行包含一个整数 T(1≤T≤100)—— 表示查询次数。
接下来的 T 行,每行包含一个字符串 s(1≤∣s∣≤100)—— 表示当前查询所用的字符串。保证该字符串仅由小写拉丁字母组成。
注意:在 hack 中,你必须设置 T=1。
输出格式
Print T lines. The i-th line should contain the answer to the i-th query.
If the answer for the i-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
输出 T 行。第 i 行应包含第 i 个查询的答案。
如果第 i 个查询存在答案,则输出给定字符串的一个字母重排,使得该重排中不包含丑陋对(ugly pairs)。你可以任意调整给定字符串中字母的顺序,但不能添加新字母或删除已有字母。你也可以保持原顺序不变。
如果存在多个答案,输出其中任意一个即可。
否则,对该查询输出 "No answer"。
输入输出样例
输入#1
4 abcd gg codeforces abaca
输出#1
cadb gg codfoerces No answer
说明/提示
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
在第一个例子中,答案“bdac”也是正确的。
第二个例子说明了只有字母表中相邻的字母才不允许相邻;相同的字母是允许的。
第三个例子有大量合法的答案。
输入解题思路,AI测评打分。不知道怎么写?