AcWing 1798. 蹄子剪刀布(Python)
原题链接
简单
作者:
严严
,
2024-12-11 04:13:41
,
所有人可见
,
阅读 2
n = int(input())
l=[]
for i in range(n):
l.append(input())
s = [[0,0,0] for i in range(n)]
if l[0] == 'H':
s[0][0] = 1
elif l[0] == 'P':
s[0][1] = 1
else:
s[0][2] = 1
for i in range(1,n):
s[i][0] = s[i-1][0]
s[i][1] = s[i-1][1]
s[i][2] = s[i-1][2]
if l[i] == 'H':
s[i][0] += 1
elif l[i] == 'P':
s[i][1] += 1
else:
s[i][2] += 1
ans = 0
for i in range(1,n-1):
temp1 = max(s[i])
temp2 = max([b-a for a,b in zip(s[i], s[n-1])])
ans = max(ans, temp1 + temp2)
print(ans)