捞鬼
发表于 2019-3-20 09:56:46
冬雪雪冬 发表于 2017-3-31 22:04
重新发了。
大神,那个(n+2)%len(list1)是怎么想出来的啊,好厉害
冬雪雪冬
发表于 2019-3-20 10:01:37
捞鬼 发表于 2019-3-20 09:56
大神,那个(n+2)%len(list1)是怎么想出来的啊,好厉害
呵呵,时间久了,我都忘了。
小强森
发表于 2019-6-19 17:23:10
# 有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),
# 凡报到3的人退出圈子,问最后留下的是原来第几号的那位
lst=[]
a=2
for i in range(100):
lst.append(1)
while True:
if a>99:
a=a-100
if lst==1:
lst=2
print(lst)
else:
a+=1
continue
a+=3
if lst.count(1)==1:
break
for i in range(100):
if lst==1:
print(i)
break
山岂乎不在高
发表于 2019-7-8 15:50:51
lista=
i = 0
while len(lista) > 1:
i += 2
while i >len(lista)-1:
i -= len(lista)
lista.pop(i)
print(lista)
山岂乎不在高
发表于 2019-7-8 15:52:03
lista=
i = 0
while len(lista) > 1:
i += 2
while i >len(lista)-1:
i -= len(lista)
lista.pop(i)
print(lista)
山岂乎不在高
发表于 2019-7-8 19:39:00
n=int(input('请输入人数:'))
lista =[i for i in range(1,n+1)
m=0
while len(lista)>1:
m+=2
while m>len(lista)-1:
m -= len(lista)
lista.pop(m)
print('%d个人,最后剩下%d'%(n,lista))
panheng
发表于 2019-8-12 14:54:36
交作业
def answer1(n):
list1 =
list2 = list1[:]
num = 0 #初始化报数号
while len(list1) != 1:
for each in list1:
num += 1 #逐个报数
if num % 3 == 0:
list2.remove(each)
print("第{}号退出".format(each))
else: #执行完一轮后替换为剔除后列表
list1 = list2
list2 = list1[:]
print("剩下的人为:{}号".format(list1))
if __name__ == "__main__":
n = int(input("请输入人数:"))
answer1(n)
克里斯保罗
发表于 2019-8-28 22:30:44
if __name__ =='__main__':
num = int(input('请输入人数:'))
list1 = []
for each in range(num):
list1.append(each+1)
i = 0
m = 0
k = 0
while m < num -1:
if list1 != 0:
k+=1
if k==3:
list1 = 0
k = 0
m+=1
i += 1
if i == num:
i = 0
i = 0
while list1 == 0:
i +=1
print(list1)
Jung
发表于 2019-11-26 09:40:38
def fun14(N):
L = []
for i in range(1,N+1):
L.append(i)
for x in L:
if((x%3)==0):
del L
print(L)
方法一:假设排号从1开始到n.函数中N为人数
BigHammer
发表于 2019-12-12 14:41:18
本帖最后由 BigHammer 于 2019-12-12 19:11 编辑
sorry
天下一统2014
发表于 2019-12-17 22:44:41
a = input("请输入多少人:")
while a.isdigit() is False:
a = input("请重新输入多少人:")
b =
c = 0
d = []
while len(b) > 1:
for i in range(len(b)):
if c != 2:
c += 1
d.append(b)
else:
c = 0
b = d[:]
d = []
print(b)
闲愚
发表于 2019-12-17 23:15:59
def solve(s):
length = len(s)
while length > 1:
for i in range(2):
a = s
del s
s.append(a)
del s
length = len(s)
return s
s = list(range(1,1001))
print(solve(s))
君子好逑
发表于 2020-4-12 13:00:02
n=input("请输入人数n:")
n=int(n)
a=[]
b=[]
for each in range(1,n+1):
a.append(each)
l=len(a)
for each in range(1,l+1):
if (each%3!=0):
m=each-1
num=a
b.append(num)
b.reverse()
print('最后留下的有:')
while(b):
m=b.pop()
print('%4d'%m,end='')
san1412
发表于 2020-5-14 08:44:49
num = int(input("请输入人数:"))
a_list = list(range(1,num+1))
n1 = 1
n2 = 0
while len(a_list) > 1:
if n1 % 3 == 0:
del a_list
n1 += 1
if n2 < len(a_list)-1:
n2 += 1
else:
n2 = 0
print("最后留下的是原来第%d号的那位"%a_list)
素手就琴
发表于 2020-6-7 15:19:50
from pythonds.basic.queue import Queue
def number_Off(namelist, num):
simqueue = Queue()
for name in namelist:
simqueue.enqueue(name)
while simqueue.size() > 1:
for i in range(num):
simqueue.enqueue(simqueue.dequeue())
simqueue.dequeue()
return namelist.index(simqueue.dequeue()) + 1
temp = input("请输入围成一圈的人名字,以空格间隔:")
namelist = temp.split()
print(number_Off(namelist, 2))
鲨鱼辣椒1
发表于 2020-8-8 11:52:38
def joseph(n,p):
a = list(range(1,n + 1))
while a:
for i in range(p):
b = a.pop(0)
a.append(b)
print(a.pop(),end = " ")
joseph(5,3)
陈尚涵
发表于 2020-8-8 17:05:33
来啦
自学小白菜
发表于 2020-8-10 19:11:06
peopleNum = int(input('Please input the total nums of people:'))
order_list=
out_num = 0
while True:
# print(out_num, order_list, peopleNum)
out_num+=2
while True:
if out_num >= peopleNum:
out_num = out_num - peopleNum
else:
break
if peopleNum == 1:
break
order_list.pop(out_num)
peopleNum-=1
print('\033
k客光
发表于 2021-1-22 12:22:30
j=1
i=int(input("请输入人数:"))
lst=
k=i
while k!=1:
for l in range(0,i):
if lst!=0:
if j==3:
lst=0
j=1
k-=1
if k==1:
break
else:
j+=1
for n in range(i):
if lst!=0:
print(lst)
逃兵
发表于 2021-1-30 17:17:31
n = int(input('请输入总人数:'))
lst =
yushu = 0
def first(lst,yushu):
temp = yushu+1
yushu = len(lst)%3+yushu
lst2=[]
for i in lst:
if temp%3==0:
lst2.append(i)
temp+=1
for i in lst2:
lst.remove(i)
if len(lst)==1:
return lst
else:
return first(lst,yushu)
luky = first(lst,yushu)
print(luky)