解题思路:
注意事项:
参考代码:
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 人评分
字符串输入输出函数 (Java代码)浏览:1440 |
多输入输出练习1 (C语言代码)浏览:1188 |
剪刀石头布 (C语言代码)浏览:1755 |
WU-拆分位数 (C++代码)浏览:785 |
【求[X,Y]内被除3余1并且被除5余3的整数的和】 (C语言代码)浏览:674 |
字符逆序 (C语言代码)浏览:646 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:489 |
数组与指针的问题浏览:718 |
蓝桥杯历届试题-翻硬币 (C++代码)浏览:890 |
钟神赛车 (C语言代码)浏览:598 |