#P16853. [GKS 2021 #E] Shuffled Anagrams

    ID: 19180 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>字符串2021Special JudgeGoogle Kick Start

[GKS 2021 #E] Shuffled Anagrams

Problem Description

Let SS be a string containing only letters of the English alphabet. An anagram of SS is any string that contains exactly the same letters as SS (with the same number of occurrences for each letter), but in a different order. For example, the word kick has anagrams such as kcik and ckki.

Now, let S[i]S[i] be the ii-th letter in SS. We say that an anagram of SS, AA, is shuffled if and only if for all ii, S[i]A[i]S[i] \ne A[i]. So, for instance, kcik is not a shuffled anagram of kick as the first and fourth letters of both of them are the same. However, ckki would be considered a shuffled anagram of kick, as would ikkc.

Given an arbitrary string SS, your task is to output any one shuffled anagram of SS, or else print IMPOSSIBLE if this cannot be done.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case consists of one line, a string of English letters.

Output Format

For each test case, output one line containing Case #xx: yy, where xx is the test case number (starting from 11) and yy is a shuffled anagram of the string for that test case, or IMPOSSIBLE if no shuffled anagram exists for that string.

2
start
jjj
Case #1: tarts
Case #2: IMPOSSIBLE

Hint

In test case #11, tarts is a shuffled anagram of start as none of the letters in each position of both strings match the other. Another possible solution is trsta (though you only need to provide one solution). However, in test case #22, there is no way of anagramming jjj to form a shuffled anagram, so IMPOSSIBLE is printed instead.

Limits

1T1001 \le T \le 100.

All input letters are lowercase English letters.

Test Set 1

1the length of S81 \le \text{the length of } S \le 8.

Test Set 2

1the length of S1041 \le \text{the length of } S \le 10^4.