CF1303C.Perfect Keyboard

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all 2626 lowercase Latin letters will be arranged in some order.

Polycarp uses the same password ss on all websites where he is registered (it is bad, but he doesn't care). He wants to assemble a keyboard that will allow to type this password very easily. He doesn't like to move his fingers while typing the password, so, for each pair of adjacent characters in ss, they should be adjacent on the keyboard. For example, if the password is abacaba, then the layout cabdefghi... is perfect, since characters a and c are adjacent on the keyboard, and a and b are adjacent on the keyboard. It is guaranteed that there are no two adjacent equal characters in ss, so, for example, the password cannot be password (two characters s are adjacent).

Can you help Polycarp with choosing the perfect layout of the keyboard, if it is possible?

Polycarp 想要组装自己的键盘。多行布局对他来说过于复杂——他的键盘将仅由一行组成,其中包含全部 2626 个小写拉丁字母,以某种顺序排列。

Polycarp 在所有他注册过的网站上都使用相同的密码 ss(这种做法很不安全,但他并不在意)。他希望组装一个能非常方便地输入该密码的键盘。他不喜欢在输入密码时移动手指,因此对于 ss 中每一对相邻字符,它们在键盘上也必须是相邻的。例如,若密码为 abacaba,则键盘布局 cabdefghi... 是完美的,因为字符 a 和 c 在键盘上相邻,且 a 和 b 在键盘上也相邻。题目保证 ss 中不存在两个相邻的相同字符,因此,例如密码不可能是 password(其中两个 s 相邻)。

如果存在完美键盘布局,请你帮助 Polycarp 选择一种;否则请判断其不可能性。

输入格式

The first line contains one integer TT (1≤T≤10001 \le T \le 1000) — the number of test cases.

Then TT lines follow, each containing one string ss (1≤∣s∣≤2001 \le |s| \le 200) representing the test case. ss consists of lowercase Latin letters only. There are no two adjacent equal characters in ss.

第一行包含一个整数 TT(1≤T≤10001 \le T \le 1000)—— 表示测试用例的数量。

接下来有 TT 行,每行包含一个字符串 ss(1≤∣s∣≤2001 \le |s| \le 200),表示一个测试用例。ss 仅由小写拉丁字母组成,且其中不存在两个相邻的相同字符。

输出格式

For each test case, do the following:

  • if it is impossible to assemble a perfect keyboard, print NO (in upper case, it matters in this problem);
  • otherwise, print YES (in upper case), and then a string consisting of 2626 lowercase Latin letters — the perfect layout. Each Latin letter should appear in this string exactly once. If there are multiple answers, print any of them.

对每个测试用例,执行以下操作:

  • 如果无法组装出一个完美键盘,则输出 NO(必须为大写字母,本题中区分大小写);
  • 否则,先输出 YES(必须为大写字母),然后输出一个由 2626 个小写拉丁字母组成的字符串——即该完美键盘的布局。该字符串中每个拉丁字母恰好出现一次。若存在多个可行解,输出任意一个即可。

输入输出样例

  • 输入#1

    5
    ababa
    codedoca
    abcda
    zxzytyz
    abcdefghijklmnopqrstuvwxyza

    输出#1

    YES
    bacdefghijklmnopqrstuvwxyz
    YES
    edocabfghijklmnpqrstuvwxyz
    NO
    YES
    xzytabcdefghijklmnopqrsuvw
    NO

输入解题思路,AI测评打分。不知道怎么写?

首页