错误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 人评分
简单编码 (C++代码)(这里推荐用switch)浏览:959 |
C语言程序设计教程(第三版)课后习题5.7 (C++代码)浏览:846 |
关于float,double变量的几点说明浏览:1810 |
字符串输入输出函数 (C语言代码)浏览:2480 |
简单的a+b (C语言代码)浏览:524 |
良心推荐——>题解1049:C语言程序设计教程(第三版)课后习题11.1 (C语言描述——简单明了,时间复杂度低)浏览:1273 |
C语言程序设计教程(第三版)课后习题8.1 (C++代码)浏览:587 |
拯救雅典娜浏览:1241 |
1169题解浏览:522 |
A+B for Input-Output Practice (C语言代码)浏览:466 |