lst=[]
n=0
i=0
i1=0
i2=0
people=int(input())
str1=input()
#print ("-------------")
lst1=str1.split(" ")
while len(lst1) > 0 :
lst.append(int(lst1.pop()))
lst.reverse()
#print (lst)
while i2 != people:
if lst[i2] != -1 :
i=0
while i < people :
if lst[i] != -1 :
while lst[i] != -1 :
i=lst[i]
lst[i1]=-1
i1=i
n+=1
else:
i+=1
else:
i2+=1
print (n)
lst=[]
n=0
i=0
i1=0
i2=0
people=int(input())
str1=input()
#print ("-------------")
lst1=str1.split(" ")
while len(lst1) > 0 :
lst.append(int(lst1.pop()))
lst.reverse()
#print (lst)
while i2 != people:
if lst[i2] != -1 :
i=0
while i < people :
if lst[i] != -1 :
while lst[i] != -1 :
i=lst[i]
lst[i1]=-1
i1=i
n+=1
else:
i+=1
else:
i2+=1
print (n)
???
這個程式碼可以AC阿,沒問題的!
lst=[]
n=0
i=0
i1=0
i2=0
people=int(input())
str1=input()
#print ("-------------")
lst1=str1.split(" ")
while len(lst1) > 0 :
lst.append(int(lst1.pop()))
lst.reverse()
#print (lst)
while i2 != people:
if lst[i2] != -1 :
i=0
while i < people :
if lst[i] != -1 :
while lst[i] != -1 :
i=lst[i]
lst[i1]=-1
i1=i
n+=1
else:
i+=1
else:
i2+=1
print (n)
???
這個程式碼可以AC阿,沒問題的!
可是我第一次:
https://drive.google.com/file/d/1wOn1H5OiUg0iTnLPlSIFlJ5stQcfP8vF/view?usp=sharing
但當第二次用同樣的程式就通過了,所以我不曉得這是甚麼情況0.0
https://drive.google.com/file/d/1LMzEUNi1AI00btHmxmodMqOdjeLpi68V/view?usp=sharing
不過,謝謝你!