当前位置:   article > 正文

蓝桥杯刷题--python-12

蓝桥杯刷题--python-12

 

3768. 字符串删减 - AcWing题库

n=int(input())
s=input()
res=0
i=0
while(i<n):
    if s[i]=='x':
        j=i+1
        while(j<n and s[j]=='x'):
            j+=1
        res+=max(j-i-2,0)
        i=j
    else:
        i+=1
print(res)

 3777. 砖块 - AcWing题库

 

# https://www.acwing.com/activity/content/code/content/5532758/
T=int(input())
def update(a,i):
    if a[i]=='W':
        a[i]='B'
    else:
        a[i]='W'
def check_(c):
    res=[]
    s_=s[:]

    for i in range (n-1):
        if s_[i]!=c:
            update(s_,i)
            update(s_,i+1)
            res.append(i)
    if s_[-1]!=c: return False
    print(len(res))

    for i in res:
        print(i + 1, end=' ')
    if len(res):
        print()
    return True


while(T):
    n=int(input())
    s=list(input())
    if not check_('B') and not check_('W'):
        print(-1)
    T-=1
 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/286358?site
推荐阅读
相关标签
  

闽ICP备14008679号