解题思路:
注意事项:
参考代码:
def cal(temp): r_index = temp.index('r') b_index = temp.index('b') cnt = 0 if temp[0] == 'w': if r_index < b_index: cnt = b_index else: cnt = r_index elif temp[0] == 'r': cnt = b_index elif temp[0] == 'b': cnt = r_index return cnt def f(s): ans = 0 for i in range(len(s)): temp = s[i:]+s[:i] lcnt = cal(temp) temp = temp[::-1] rcnt = cal(temp) if lcnt+rcnt > ans: ans = lcnt + rcnt print(ans) if __name__ == '__main__': s = input().strip() f(s)
0.0分
0 人评分
C语言训练-求矩阵的两对角线上的元素之和 (C语言代码)浏览:1097 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:564 |
简洁的代码浏览:1409 |
点我有惊喜!你懂得!浏览:1395 |
C语言程序设计教程(第三版)课后习题6.11 (C语言代码)for循环浏览:1131 |
【密码】 (C语言代码)浏览:333 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:1007 |
C语言程序设计教程(第三版)课后习题6.11 (C语言代码)浏览:549 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:594 |
1157题解浏览:718 |