#abc345c. C - One Time Swap
C - One Time Swap
Points: points
问题陈述
给定一个字符串 。找出通过执行以下操作恰好一次可以得到的字符串数量。
- 设 为 的长度。选择一对整数 ,使得 并交换 中的第 个和第 个字符。
可以证明,在这个问题的约束条件下,你总是可以执行这个操作。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a string . Find the number of strings that can result from performing the following operation exactly once.
- Let be the length of . Choose a pair of integers such that and swap the -th and -th characters of .
It can be proved that you can always perform it under the constraints of this problem.
Constraints
- is a string of length between and , inclusive, consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
Output
Print the number of strings that can result from performing the operation in the problem statement exactly once on .
Sample Input 1
abc
Sample Output 1
3
The length of is , so is satisfied by three pairs of integers : , , and .
- Swapping the -st and -nd characters of results in being
bac
. - Swapping the -st and -rd characters of results in being
cba
. - Swapping the -nd and -rd characters of results in being
acb
.
Therefore, the operation on abc
results in one of the three strings: bac
, cba
, and acb
, so print .
Sample Input 2
aaaaa
Sample Output 2
1
Swapping any two characters results in remaining aaaaa
. Thus, only one string can result from the operation.
update @ 2024/5/16 17:16:45