本文共 863 字,大约阅读时间需要 2 分钟。
为了解决这个问题,我们需要编写一个程序来帮助小明确定微博转发抽奖活动的中奖名单。程序需要从转发的网友中按固定间隔选出中奖者,并确保每个网友只能中奖一次。
m, n, s = map(int, input().split())names = [input().strip() for _ in range(m)]result = []used = set()i = s - 1 # 转换为0索引while i < m: current = names[i] if current not in used: used.add(current) result.append(current) i += nif result: for name in result: print(name)else: print("Keep going...") input().split()读取M、N和S的值,然后读取接下来的M行昵称。result列表用于存储中奖名单,used集合用于记录已中奖的网友。这个方法确保我们正确地从指定位置开始,每隔固定间隔选出中奖者,并避免重复中奖,满足题目的所有要求。
转载地址:http://vyqoz.baihongyu.com/