D


私信TA

用户名:ALS1111

访问量:19541

签 名:

等  级
排  名 51
经  验 10958
参赛次数 0
文章发表 132
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

python-芯片测试
浏览:217
python-产生数
浏览:143
python-夺宝奇兵
浏览:242

解题思路:

注意事项:

参考代码:

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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区