Python实现了约瑟夫学生死亡的比赛

Python实现了约瑟夫学生死亡的比赛

标题:

30人在一条船上,超载,须要15人下船,所以人们排成了一队,列队的场所即为她们的编号,从第一个发端报数,从1数到9,数到9的人下船,如许轮回来往,直到船上仅剩下15报酬止,那么有哪些人下船呢?

people = {}

for i in range(1,31):

people[i] = 1

check = 0

i = 1

j = 0

while i <= 31:

if i == 31:

i = 1

elif j == 15:

break

else:

if people[i] == 0:

i += 1

continue

else:

check += 1

if check == 9:

people[i] = 0

check = 0

print("{}号下船了!".format(i))

j+=1

else:

i+=1

continue

分享到 :
PHP8匹配语法
2021-03-30 下一篇

Leave a Reply

Your email address will not be published. Required fields are marked *