解题思路:
通过判断取出的链子中不重复元素个数来判断是否符合题意规则。
注意事项:
输入样例中有例子结尾有多余空格,需要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 人评分
简单的a+b (C语言代码)浏览:685 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:661 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:678 |
【偶数求和】 (C语言代码)浏览:556 |
【偶数求和】 (C语言代码)浏览:431 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:514 |
C二级辅导-公约公倍 (C语言代码)浏览:483 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:376 |
拆分位数 (C语言代码)浏览:441 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:581 |