错误9%、实在是不知道为什么。
n = int(input()) s = list(input()) s1 = s[::-1] total = 0 """判断是否可以做回文串""" def check(S): count = 0 if len(S)%2 ==0: for s in S: if S.count(s) != 2: return False else: for s in S: if S.count(s) != 2: count += 1 if count >= 2: return False return True def swap(s,s1,n): global total if check("".join(s)): for i in range(n//2): a = s[i] if s.count(a) != 1: total += s1.index(a) s1.pop(s1.index(a)) s = s1[::-1] else: total += n//2 - i s1.pop(a) s = s1[::-1] swap(s,s1,n) if total != 0: print(total) else: print("Impossible")
0.0分
3 人评分