This action will force synchronization from Yonja/python100, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
#!/usr/bin/python# -*- coding: UTF-8 -*-"""题目:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。"""if __name__ == '__main__':n = int(raw_input('input the total numbel:\n'))num = []for i in range(n):num.append(i + 1)i = 0k = 0m = 0#总体思路就是把报数是3的num列表元素全部设为0,最后判断哪个不是0哪个就是最后剩下的while m < n - 1: # 这里的m是设为0的数目,从0开始一共n-1个if num[i] != 0: k += 1if k == 3:num[i] = 0k = 0m += 1i += 1if i == n: i = 0i = 0while num[i] == 0: i += 1print num[i]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。