There’re N magicka spells. Each spell is composed by several digits 1~9.
123, 7 are valid spells, but a12, 0, 073 are not.
The damage of the spell is the decimal number represented by itself.
We want to get largest damage by sort the digits of spell from large to small.
Let’s call the sorted spell as critical spell.
For example, 7731 is the critical spell of 1377, 7317, 3717, … .
Your task is to find all kinds of critical spells of N spells, and output them without repetition in decreasing order by their damages.
You may consider the following algorithm:
For sorting, you can use the following code:
char s[30];
…
int len = strlen(s);
for (int i = 0; i < len; i++) {
for (int j = 0; j < len - i - 1; j++) {
if (s[j] < s[j + 1]) {
/*swap s[j] and s[j+1]*/
}
}
}
|
Testcase 1 ~ 5: |si| = |sj| for all i, j. |si| ≤ 8, for all i
Testcase 6 ~ 8: |si| ≠ |sj| for some i, j. |si| ≤ 8, for all i
Testcase 9 ~ 10: |si| ≠ |sj| for some i, j. |si| ≤ 50, for all i
There’s N on the first line.
There’s a spell si on the each of following N lines.
It’s guaranteed that:
Print the critical spells without repetition in decreasing order on each line.
Remember ‘\n’ on the end of each line.