No.170 Swap String (Easy)
タグ : / 解いたユーザー数 444
作問者 :
Problem Statement
A string $S$ of at most $8$ characters is given as input.
Among the characters forming this string $S$, you may perform the operation "swap any $2$ adjacent characters" any number of times.
Find the number of distinct strings that can be made.
However, a string identical to the input string $S$ is not counted.
Input
S
The string $S$ is given on the $1$st line. $( 1 \leq |S| \leq 8 ) $
The string $S$ consists only of uppercase letters ('A'–'Z').
Output
Output the number of distinct strings that can be made by the operation in the problem statement (excluding the input string $S$ itself),
as an integer.
Sample
Sample 1
Input
ABC
Output
5
The strings that can be made by swapping $2$ adjacent characters of the string "ABC" some number of times are the following $6$.
ABC ACB
BAC BCA
CAB CBA
However, since the input string itself is not counted, $5$ distinct strings excluding "ABC" can be made.
Sample 2
Input
DDDDDD
Output
0
No matter how many times you swap, no string other than "DDDDDD" can be made.
Since the input string itself is not counted, the answer is $0$ distinct strings, excluding "DDDDDD".
Sample 3
Input
XYZYX
Output
29
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。