0
点赞
收藏
分享

微信扫一扫

蓝桥杯刷题(九)

1.三国游戏

在这里插入图片描述

代码

#输入数据
n=int(input())
Xli=list(map(int,input().split()))
Yli=list(map(int,input().split()))
Zli=list(map(int,input().split()))
#分别计算X-Y-Z/Y-Z-X/Z-X-Y并排序
newXli = sorted([Xli[i] - Yli[i] - Zli[i] for i in range(n)],reverse=True)
newYli = sorted([Yli[i] - Xli[i] - Zli[i] for i in range(n)],reverse=True)
newZli = sorted([Zli[i] - Xli[i] - Yli[i] for i in range(n)],reverse=True)
cnt=-1
#初始化每国士兵数量
x=y=z=0
#统计事件
for i in range(n):
    x+=newXli[i]
    y+=newYli[i]
    z+=newZli[i]
    if x>0 or y>0 or z>0:
        cnt=max(cnt,i+1)
#输出结果
if cnt!=1:
    print(cnt)
else:
    print(-1)

2.填充

在这里插入图片描述

代码

s = input()
n = len(s)
l = ['00','11','0?','1?','?0','?1','??']
cnt = 0
i = 0
while i < n:
    if s[i:i+2] in l: # 在列表的元素都个数加一然后越过已判断子串
        cnt+=1
        i+=2
    else:
        i+=1
print(cnt)
举报

相关推荐

0 条评论