我這樣寫有甚麼瑕疵?最高只能拿到85%的分數
(Python Regular Expression)
import re while True: try: k = int(input()) s = input() if k == 1 and len(s) == 1: print(1) else: regC = re.compile(f'([A-Z]{{{k}}}[a-z]{{{k}}})*([A-Z]{{{k}}})?') regL = re.compile(f'([a-z]{{{k}}}[A-Z]{{{k}}})*([a-z]{{{k}}})?') moC = re.finditer(regC, s) moL = re.finditer(regL, s) best = 0 if moC: for c in moC: l = len(c.group()) if l > best: best = l if moL: for l in moL: le = len(l.group()) if le > best: best = le print(best) except: break