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

相关推荐
qq_459234427 天前
【题库】| 商用密码应用安全性评估从业人员考核题库(四十)
职场和发展·密码学·学习方法·考核·商用密码·商用密码应用安全性评估·密评
敲敲了个代码7 天前
[特殊字符] 空数组的迷惑行为:为什么 every 为真,some 为假?
前端·javascript·react.js·面试·职场和发展
诚思报告YH7 天前
视频面试软件市场洞察:2026 - 2032年复合年均增长率(CAGR)为10.3%
面试·职场和发展
重生之后端学习7 天前
74. 搜索二维矩阵
开发语言·数据结构·算法·职场和发展·深度优先
tyb3333337 天前
leetcode:吃苹果和队列
算法·leetcode·职场和发展
Pitiless-invader7 天前
MySQL 相关知识及面试问题汇总
面试·职场和发展
重生之后端学习7 天前
35. 搜索插入位置
java·数据结构·算法·leetcode·职场和发展·深度优先
逆境不可逃7 天前
【从零入门23种设计模式08】结构型之组合模式(含电商业务场景)
线性代数·算法·设计模式·职场和发展·矩阵·组合模式
筱昕~呀7 天前
冲刺蓝桥杯-DFS板块(第二天)
算法·蓝桥杯·深度优先
zheshiyangyang7 天前
前端面试基础知识整理【Day-10】
前端·面试·职场和发展