1.三国游戏
代码
n=int(input())
Xli=list(map(int,input().split()))
Yli=list(map(int,input().split()))
Zli=list(map(int,input().split()))
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)