#31631: Python 狀態機解法


seer852741@gmail.com (St418)

學校 : 國立中央大學
編號 : 170226
來源 : [114.24.161.39]
最後登入時間 :
2024-01-05 19:57:56
c462. apcs 交錯字串 (Alternating Strings) -- apcs | From: [220.129.100.13] | 發表日期 : 2022-08-11 21:30

k = int(input())
text = input()
case = text[0].isupper()
accumulation = 0
state = 0
max_state = 0
for t in text:
    if t.isupper() is case:
        accumulation = (accumulation + 1) % k
        if not accumulation:
            case = not case
            state += k
            if state > max_state:
                max_state = state
    elif accumulation:
        case = not case
        accumulation = 1
        state = 0
    else:
        state = k
print(max_state)
 
ZeroJudge Forum