51 lines
877 B
Python
51 lines
877 B
Python
# import re
|
|
#
|
|
# with open('24_7.txt', 'r') as file:
|
|
# data = file.readline()
|
|
#
|
|
# data = re.sub('CD', '--', data)
|
|
#
|
|
# not_CD = r'(-?[^-]*)'
|
|
#
|
|
# CD_and_any = r'(?:--[^-]*){160}-?'
|
|
# la_CD_group = rf'(?=({CD_and_any}))'
|
|
#
|
|
# pattern = rf'{not_CD}{la_CD_group}'
|
|
#
|
|
# matches = re.findall(pattern, data)
|
|
#
|
|
# res = max([len(match[0] + match[1])
|
|
# for match in matches])
|
|
|
|
|
|
# f = open('24_7.txt').read().strip()
|
|
# a = []
|
|
# for i in range(len(f) - 1):
|
|
# if f[i]+f[i+1] == 'CD':
|
|
# a.append(i)
|
|
# print(max([p1-p for p,p1 in zip(a, a[161:])]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
f = open('24_7.txt').read().strip()
|
|
cd = 0
|
|
two = 0
|
|
max_len = 0
|
|
|
|
for i in range(len(f)-1):
|
|
if f[i] + f[i+1]== 'CD':
|
|
cd += 1
|
|
|
|
while cd > 160:
|
|
if f[two]=='C' and f[two+1] == 'D':
|
|
cd -= 1
|
|
two += 1
|
|
|
|
if cd == 160:
|
|
max_len = max(max_len, i - two+2)
|
|
|
|
print(max_len) |