解题思路:
通过判断取出的链子中不重复元素个数来判断是否符合题意规则。
注意事项:
输入样例中有例子结尾有多余空格,需要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语言训练-大、小写问题 (C语言代码)浏览:2349 |
C语言训练-计算1977!* (C++代码)浏览:847 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:624 |
大神老白 (C语言代码)浏览:638 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:993 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:640 |
WU-图形输出 (C++代码)浏览:800 |
DNA (C语言代码)浏览:540 |
1009题解浏览:721 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:606 |