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

相关推荐
呆呆的小鳄鱼39 分钟前
leetcode:518. 零钱兑换 II[完全背包]
算法·leetcode·职场和发展
小莫分享2 小时前
2023年最新总结,阿里,腾讯,百度,美团,头条等技术面试题目,以及答案,专家出题人分析汇总。
java·后端·面试·职场和发展
byte轻骑兵3 小时前
BLE低功耗设计:从广播模式到连接参数优化的全链路分析与真题解析
面试·职场和发展
緈福的街口21 小时前
【leetcode】2236. 判断根节点是否等于子节点之和
算法·leetcode·职场和发展
程序员三藏1 天前
如何使用Pytest进行测试?
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest
Z字小熊饼干爱吃保安1 天前
面试技术问题总结一
数据库·面试·职场和发展
运维开发王义杰1 天前
打破技术债困境:从“保持现状”到成为变革的推动者
运维·职场和发展
Coding小公仔1 天前
LeetCode 8. 字符串转换整数 (atoi)
算法·leetcode·职场和发展
GEEK零零七1 天前
Leetcode 393. UTF-8 编码验证
算法·leetcode·职场和发展·二进制运算
古希腊被code拿捏的神2 天前
【Flutter】面试记录
flutter·面试·职场和发展