1 Star 0 Fork 2

eetigite/python100

forked from Yonja/python100 
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
python69.py 723 Bytes
Copy Edit Raw Blame History
zhangweizhi authored 2016-06-04 15:16 +08:00 . the 100 theme
#!/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 = 0
k = 0
m = 0
#总体思路就是把报数是3的num列表元素全部设为0,最后判断哪个不是0哪个就是最后剩下的
while m < n - 1: # 这里的m是设为0的数目,从0开始一共n-1个
if num[i] != 0: k += 1
if k == 3:
num[i] = 0
k = 0
m += 1
i += 1
if i == n: i = 0
i = 0
while num[i] == 0: i += 1
print num[i]
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/eetigite/python100.git
git@gitee.com:eetigite/python100.git
eetigite
python100
python100
master

Search