DEBUG example

mail@pastecode.io avatar
unknown
python
2 years ago
1.3 kB
3
Indexable
Never
DEBUG = True
def log(s):
    if DEBUG:
        print(s)

k = int(input())
w = input()
a = []
b = []
s = []
d = []
f = []

for i in w:
    if i.isupper():
        a += [1]
    else:
        a += [2]

for _ in range(k):
    b += [1]
    s += [2]

r = 0
while(r+k <= len(a)):
    if a[r:(r+k)] != b and a[r:(r+k)] != s:
        r += 1
    else:
        d += [r]
        r += 1
# 檢查索引值都進去d了嗎?
log(d)    
if d == []:
        print(0)
else:
    for v in d:     
        
        counter = 0
        if a[v:(v+k)] == b:
            before = 1
            counter += k
        elif a[v:(v+k)] == s:
            before = 2
            counter += k
        for i in range(v+k, len(a)-k, k):
            if a[i:(i+k)] == b and before == 2:
                counter += k
                before = 1
            elif a[i:(i+k)] == s and before == 1:
                counter += k
                before = 2
            else:
                f += [counter]
                counter = 0
                break
            # 檢查counter都正確嗎?
            log('before:'+str(before)+', counter:'+str(counter))
        # 檢查counter是否確實加入f串列?
        log('v: '+str(v)+', f:'+str(f))
        # 如果最長子字串有包含最後的字母,就進不到else
        if counter != 0:    f += [counter]
    print(max(f))