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

相关推荐
元亓亓亓13 小时前
LeetCode热题100--105. 从前序与中序遍历序列构造二叉树--中等
算法·leetcode·职场和发展
测试老哥13 小时前
Selenium 使用指南
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
仙俊红16 小时前
LeetCode每日一题,20250914
算法·leetcode·职场和发展
前端小超超1 天前
capacitor配置ios应用图标不同尺寸
ios·蓝桥杯·cocoa
睡不醒的kun1 天前
leetcode算法刷题的第三十四天
数据结构·c++·算法·leetcode·职场和发展·贪心算法·动态规划
吃着火锅x唱着歌1 天前
LeetCode 1446.连续字符
算法·leetcode·职场和发展
武子康2 天前
AI-调查研究-76-具身智能 当机器人走进生活:具身智能对就业与社会结构的深远影响
人工智能·程序人生·ai·职场和发展·机器人·生活·具身智能
Nan_Shu_6142 天前
Web前端面试题(1)
前端·面试·职场和发展
YuTaoShao2 天前
【LeetCode 每日一题】3000. 对角线最长的矩形的面积
算法·leetcode·职场和发展
007php0072 天前
Redis高级面试题解析:深入理解Redis的工作原理与优化策略
java·开发语言·redis·nginx·缓存·面试·职场和发展