解题思路:
通过判断取出的链子中不重复元素个数来判断是否符合题意规则。
注意事项:
输入样例中有例子结尾有多余空格,需要strip()掉
参考代码:
def collect(string): cnt, temp = 2, 0 for i in range(1, len(string)): temp = i if len(set(string[:i])) < 2 or \ (len(set(string[:i])) == 2 and 'w' in string[:i]): cnt = len(string[:i]) else: break if temp == len(string) - 1: return cnt if temp != len(string): cnt_0 = 0 for j in range(-2, -(len(string) - temp) - 1, -1): if len(set(string[-1:j:-1])) < 2 or \ (len(set(string[-1:j:-1])) == 2 and 'w' in string[-1:j:-1]): cnt_0 = len(string[-1:j:-1]) else: return cnt + cnt_0 n, temp = input().strip(), [] for i in range(1, len(n) - 1): n = n[1:] + n[0] temp.append(n) print(max(map(lambda x: collect(x), temp)))
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:946 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:735 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:476 |
C语言程序设计教程(第三版)课后习题6.6 (C语言代码)浏览:350 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:534 |
1009题解浏览:752 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:902 |
星期判断机 (C语言代码)浏览:859 |
字符串比较 (C语言代码)浏览:685 |
C二级辅导-温度转换 (C语言代码)浏览:550 |