#30774: Python解法用def


Alenissmart (Alenissmart)

學校 : 不指定學校
編號 : 146407
來源 : [36.231.75.224]
最後登入時間 :
2024-06-17 17:25:10
c462. apcs 交錯字串 (Alternating Strings) -- apcs | From: [1.169.28.215] | 發表日期 : 2022-06-11 17:40

k = int(input())
string = input()
zero_one = ""
l = []

for each in string:
    if 65 <= ord(each) <= 90:
        zero_one += "0"
    elif 97<= ord(each) <= 122:
        zero_one += "1"

test = ""
total = 0

for each in zero_one:
    if test == "":
        test = each
        total += 1
    elif test == each:
        total += 1
    else:
        l.append(total)
        total = 1
        test = each
l.append(total)

def find(k,n):
    global leng
    if n == len(l):
        pass
    elif l[n] > k:
        if leng == 0:
            leng += k
            find(k,n+1)
        else:
            leng += k
    elif l[n] == k:
        leng += k
        find(k,n+1)

maxleng = 0
for i in range(len(l)):
    leng = 0
    find(k,i)
    if leng>maxleng:
        maxleng = leng

print(maxleng)

 
ZeroJudge Forum