{ "question_id": 7431923, "question_title": "运气最佳游戏", "question_content": "
运气最佳游戏:\n一群人排成一圈,按“1,2,......n”依次编号。然后从第1个人开始数,数到m把 踢出圈,其后的人再从1开始数,数到m,再把它踢出去......\n如此不停地进行下去直到最后只剩下一个人为止,那个人就是运气最佳。\n具体需求如下所示。\n编写函数模拟该游戏。\n根据用户输入的m和n,指定人的总数n和踢出第m个人。\n最后输出运气最佳的人的编号。
", "difficulty": "简单", "answer_id": 53400791, "answer_content": "\nn = eval(input("请输入总人数:"))\nm = eval(input("请输踢出第几个人:"))\n\nlist1 = []\nfor i in range(1, n+1):\n list1.append(i)\n\nwhile len(list1) != 1:\n if len(list1) >= m:\n list1 = list1[m:] + list1[0:m-1]\n print(list1)\n elif len(list1) < m:\n while len(list1) != 1:\n if m%len(list1) != 0:\n list1 = list1[m%len(list1):] + list1[0:m%len(list1)-1]\n else:\n list1 = list1[0:-2]\n\nprint("最佳运气人编号为:%d号!"%list1[0])
\n\n这个可以吗?
\n", "tag_name": "python", "python": "n = eval(input(\"请输入总人数:\"))\nm = eval(input(\"请输踢出第几个人:\"))\nlist1 = []\nfor i in range(1, n+1):\n list1.append(i)\nwhile len(list1) != 1:\n if len(list1) >= m:\n list1 = list1[m:] + list1[0:m-1]\n print(list1)\n elif len(list1) < m:\n while len(list1) != 1:\n if m%len(list1) != 0:\n list1 = list1[m%len(list1):] + list1[0:m%len(list1)-1]\n else:\n list1 = list1[0:-2]\nprint(\"最佳运气人编号为:%d号!\"%list1[0])\n", "topic_link": "https://bbs.csdn.net/topics/600470296", "status": 0, "keywords": "算法初阶,基础知识,函数的增长,标准记号与常用函数", "license": "csdn.net", "notebook": { "python": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/python/3.ipynb?type=file" } }