# encoding = utf-8
# 开发者:xxx
# 开发时间: 0:21
# "Stay hungry,stay foolish."
def huiwen(n, s): # 判断能不能组成回文数
temp_D = set()
temp_S = set()
if n % 2 == 0:
for i in range(26):
if s.count(chr(ord('a') + i)) % 2 != 0: # 如果某个字符不是偶数个
print('Impossible')
return False
else:
return True
else:
for j in range(26):
word = chr(ord('a') + j)
# 统计了字符串 s 中特定字符(ASCII 值在 'a' 之后 j 个字符)出现的次数。
if s.count(word) % 2 == 0:
temp_D.add(word) # 把个数是奇数个的字符放进temp
else:
temp_S.add(word)
if len(temp_S) >= 2:
print('Impossible')
return False
else:
return True
# 贪心策略:
# 对于偶数的字符串,我们从第一个开始遍历,再倒序遍历出同样的&