#41725: 我這樣寫問題出在哪?


likangchiou248@gmail.com (邱立康)

學校 : 國立臺南第一高級中學
編號 : 276859
來源 : [210.70.138.4]
最後登入時間 :
2024-11-20 14:26:51
c462. apcs 交錯字串 (Alternating Strings) -- apcs | From: [36.238.169.73] | 發表日期 : 2024-08-20 16:01

我這樣寫有甚麼瑕疵?最高只能拿到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
 
ZeroJudge Forum