当前位置: 首页 > news >正文

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

http://www.lryc.cn/news/306524.html

相关文章:

  • LeetCode LCR 085.括号生成
  • 抖音视频评论数据提取软件|抖音数据抓取工具
  • 【web】云导航项目部署及环境搭建(复杂)
  • 软件测试人员必会的linux命令
  • Mac使用K6工具压测WebSocket
  • 小程序--vscode配置
  • linux僵尸进程
  • 【web | CTF】攻防世界 Web_php_unserialize
  • Vue3中的select 的option是多余的?
  • 考研408深度分析+全年规划
  • 【算法笔记】ch01_01_0771 宝石与石头
  • jQuery瀑布流画廊,瀑布流动态加载
  • 玩转ChatGPT:参考文献速查
  • [设计模式Java实现附plantuml源码~行为型]算法的封装与切换——策略模式
  • ​【C语言】长篇详解,字符系列篇3-----strstr,strtok,strerror字符串函数的使用【图文详解​】
  • 如何实现一个K8S DevicePlugin?
  • Android LruCache源码分析
  • 如何使用Inno Setup制作Unity构建程序的Windows安装程序
  • linux 面试题
  • 嵌入式中逻辑分析仪基本操作方法
  • ONLYOFFICE 桌面编辑器 v8.0 更新内容详细攻略
  • 2024-2-22 作业
  • 2.1 RK3399项目开发实录-升级固件介绍(物联技术666)
  • Uniapp + VUE3.0 实现双向滑块视频裁剪效果
  • 【算法小讲堂】#1 贪心算法
  • 判断当前shell版本
  • 如何实现两个电脑之间通过以太网(网线)实现文件互传
  • Jenkins 中部署Nodejs插件并使用,并构建前端项目(3)
  • VUE为什么有的属性要加冒号
  • 微信小程序 --- wx.request网络请求封装