蓝桥杯3519 填充 | 分类讨论

题目传送门


很简单,遍历一次字符串,将'?'作为0或1处理,发现00和11统计次数即可。


python 复制代码
s = str(input())
cnt = 0
arr = ['00', '11', '0?', '?0', '1?', '?1', '??']
i=0
while i < len(s)-1:
    if s[i:(i+2)] in arr:
        i += 2
        cnt += 1
    else:
        i += 1
print(cnt)

END✨

相关推荐
AALoveTouch21 分钟前
大某麦演唱会门票如何自动抢
python
忧陌6061 小时前
Day22打卡-复习
python
Sylvan Ding2 小时前
PyTorch Lightning实战 - 训练 MNIST 数据集
人工智能·pytorch·python·lightning
水银嘻嘻3 小时前
web 自动化之 Unittest 应用:报告&装饰器&断言
前端·python·自动化
攻城狮7号3 小时前
Python爬虫第20节-使用 Selenium 爬取小米商城空调商品
开发语言·数据库·爬虫·python·selenium
虚空之月&&轮舞者5 小时前
Python与矢量网络分析仪3671E:自动化测试(Vscode)
网络·vscode·python·射频工程
李昊哲小课5 小时前
tensorflow-cpu
大数据·人工智能·python·深度学习·数据分析·tensorflow
梁下轻语的秋缘6 小时前
每日c/c++题 备战蓝桥杯(P2241 统计方形(数据加强版))
c语言·c++·蓝桥杯
小彭律师10 小时前
数字化工厂中央控制室驾驶舱系统架构文档
python
old_power11 小时前
【Python】PDF文件处理(PyPDF2、borb、fitz)
python·pdf