哪裡有錯或更好的解法要多多指教喔~
k = int(input())
data = list(input())
test = str()#0011
ans = str()
datat = str()#list()轉換
1 用str.islower()確認字母是不是小寫->bool->int
#確認大小寫
for i in data:
if i.islower():
datat +='0'
else:
datat += '1'
2
#k長度
zore = '0'*k
one = '1'*k
3
n = 0#n是用來計算test not in datat的,會有兩次
i = 0#看接下來是0或1
while n <= 1:
if test in datat:
ans = test
else:
n += 1
if i%2 == 1:
test = test + one
else:
test = test + zore
i += 1
4
#輸出
if (one+ans) in datat:#一開始test從'0'*k開始查,可能會漏掉從'1'*k開始的
print(len(ans+one))
else:
print(len(ans))