题解 | #报数游戏#

报数游戏

https://www.nowcoder.com/practice/b29badef4e4545bca349e407b378bb88

n = int(input())    # 输入总人数
m = int(input())    # 输入牛牛所在位置
n_list = []         # 创建循环列表
del_list = []       # 删除的人列表
nub = 0             # nub到3,总人数减1
if m <= n and n > 2:    # 判断输入的m和n是否复合要求
    for i in range(1,n+1):
        n_list.append(i)    # 把总人数分成一个一个单个的人,存入循环列表中 
    for j in n_list:    # 遍历循环列表
        nub += 1
        if nub < 3:
            n_list.append(j)    # 遍历循环列表,nub数小于3,在遍历列表末尾加上该元素
        while nub == 3:
            nub = 0
            del_list.append(j)  # nub到达3时,把这个人添加到删除列表中
        if m in del_list:       # 如果牛牛在删除列表中,循环结束
            break
print(len(del_list))            # 删除列表的长度表明牛牛是第几个出来                    

全部评论

相关推荐

点赞 评论 收藏
分享
06-28 22:48
已编辑
广东金融学院 Java
小浪_Coding:学院本+这俩项目不是buff叠满了嘛
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务