n = int(input())
g = list(map(int, input().split()))
found = False
j = 0
if g.count(1) < 2:
print(0)
else:
while not found:
if g[j] == 1:
g[0:j] = [1 for i in range(j)]
found = True
j+=1
found = False
j = n-1
while not found:
if g[j] == 1:
g[j:n] = [1 for i in range(n-j)]
found = True
j-=1
for i in range(n):
if g[i] == 9:
if g[i+1] != 9:
if g != 0:
g[i-1] = 1
if g != n:
g[i+1] = 1
else:
if g != 0:
g[i-1] = 1
print(g.count(0))'我這樣有AC, 少設想欄杆小於2的情況和兩隻害蟲連在一起的情況
n = int(input())
g = list(map(int, input().split()))
found = False
j = 0
if g.count(1) < 2:
print(0)
else:
while not found:
if g[j] == 1:
g[0:j] = [1 for i in range(j)]
found = True
j+=1
found = False
j = n-1
while not found:
if g[j] == 1:
g[j:n] = [1 for i in range(n-j)]
found = True
j-=1
for i in range(n):
if g[i] == 9:
if g[i+1] != 9:
if g != 0:
g[i-1] = 1
if g != n:
g[i+1] = 1
else:
if g != 0:
g[i-1] = 1
print(g.count(0))'我這樣有AC, 少設想欄杆小於2的情況和兩隻害蟲連在一起的情況
感謝電神,我變成88%了,我確實沒考慮到99的情況,但欄杆小於2的情況我應該是可以的,因為我是讓程式碰到1才加回去,因此沒碰到1的話,應不會有加回去的情況。
想請問還有哪裡可能會是沒有考慮到的情況,感謝電神