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
 

Logo

2万人民币佣金等你来拿,中德社区发起者X.Lab,联合德国优秀企业对接开发项目,领取项目得佣金!!!

更多推荐