有30人围成一圈,从1到30依次编号每个人开始报数,报到9的自动离开。当有人离开时,后一个人开始重新从1报数,以此类推。求离开的前10人编号。
a=[x for x in range(1,31)]
for i in range(10):
b=a.pop(8)
print(b)
a=a[8:]+a[:8]#将离开位置分段拼接,使得下一个人变成首位
# print(a)
做法比较粗暴,不过应该没问题
```python
d = list(range(1, 31))
H = []
n = 0
condition = True
while condition:
condition = False
for i in range(1, len(d)+1):
n += 1
if n == 9:
H.append(d[i - 1])
d.remove(d[i - 1])
n = 0
condition = True
break
print(H[0:10])
[9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
```