(Python)给定一个只包含大写英文字母的字符串S,要求你给出对S重新排列的所有不相同的排列数

如:S为ABA,则不同的排列有ABA、AAB、BAA三种。

输入

输入一个长度不超过10的字符串S,确保都是大写的。

输出

输出S重新排列的所有不相同的排列数(包含自己本身

import math
from collections import Counter

string = input()
n = len(string)
down_list = []
for m, n in Counter(string).items():
    if n > 1:
        down_list.append(math.factorial(n))
up = math.factorial(len(string))  
down = 1
for i in down_list:
    down *= i
print(up//down)

个人解法,如有错误,还望指正,Thanks♪(・ω・)ノ

猜你喜欢

转载自blog.csdn.net/qq_43486538/article/details/132911707