QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 256 MB 總分: 100

#8829. 回文恐惧症

统计

Chuck McGill 患有电磁波过敏症:他害怕电力。但你知道吗,他也害怕回文?

有一次,他收到 Jimmy 送的一个字符串 $s$ 作为生日礼物。他想重新排列其中的字符,得到字符串 $t$,使得以下条件成立:

  • 对于每一个 $i = 2, 3, \dots, |s|$,字符串 $t_1t_2 \dots t_i$ 都不是回文。

你能帮帮他吗?

提醒一下,如果一个字符串 $s$ 从前往后读和从后往前读是一样的,则称其为回文。例如,aibohphobia 就是一个回文。

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 10^5$),表示测试用例的数量。接下来是各测试用例的描述。

每个测试用例仅包含一行,为一个由小写拉丁字母组成的字符串 $s$。

保证所有测试用例中 $s$ 的长度之和不超过 $10^6$。

输出格式

对于每个测试用例,如果无法通过重排 $s$ 中的字符满足条件,输出 NO。

否则,输出 YES。并在下一行输出一个字符串 $t$。它应该是 $s$ 中字符的一种重排,且必须满足题目中的条件。

你可以以任意大小写形式输出 YES 和 NO(例如,yEs, yes, Yes 都会被视为肯定回答)。

样例

样例输入 1

5
a
sos
abba
icpc
tenet

样例输出 1

YES
a
YES
oss
NO
YES
icpc
YES
tente

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.