蓝桥杯刷题--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

相关推荐
哎写bug的程序员11 小时前
leetcode复盘(1)
算法·leetcode·职场和发展
qq_5344525213 小时前
【算法 day02】LeetCode 209.长度最小的子数组 | 59.螺旋矩阵II
java·算法·leetcode·职场和发展
求职小程序华东同舟求职1 天前
互联网校招腾讯26届校招暑期实习综合素质测评答题攻略及真题题库
面试·职场和发展·求职招聘·求职
测试19981 天前
2025软件测试面试题汇总(接口测试篇)
自动化测试·软件测试·python·测试工具·面试·职场和发展·接口测试
GalaxyPokemon1 天前
LeetCode - LCR 173. 点名
算法·leetcode·职场和发展
骑驴看星星a1 天前
P10987 [蓝桥杯 2023 国 Python A] 火车运输
职场和发展·蓝桥杯
爱coding的橙子1 天前
每日算法刷题Day31 6.14:leetcode二分答案2道题,结束二分答案,开始枚举技巧,用时1h10min
算法·leetcode·职场和发展
潘小磊1 天前
高频面试之6Hive
大数据·hive·面试·职场和发展
a东方青2 天前
[蓝桥杯 2023 国 B] AB 路线 (BFS)
c++·算法·职场和发展·蓝桥杯·宽度优先