跪求python小程序!急急急!

我是编程渣渣,一窍不通...急求一些20行到50行的小程序!简单的就行!希望大神伸出援手
希望是实用一点的,不要太复杂,我才上了几节课,但要交一个程序,实在是太难为我了。万分感谢 T^T

# -*- coding: utf-8 -*-
"""
:created on: 2015年5月18日

:author: Chuanqing Qin
:contact: [email protected]

这个小程序是为了解决约瑟夫环这个问题。100个人报数偶数测剔除,剔除之后再次报数,偶数还是
剔除,知道余下最后一个人,问这个人的编号。
本算法的实现比较低效,但是完成了相关的功能,过程如下:、
首先将编号放入一个列表,之后循环列表,将编号是奇数的标志为1,
一次循环之后将所有为-1的值删除,之后进入下次循环,直到最后的列表
还剩下一个元素。
"""

def josephCircle(number_of_people):
    temp_prision = [i for i in range(1, number_of_people + 1)]
    while temp_prision.count(-1) != len(temp_prision) - 1:
        for i in xrange(len(temp_prision)):
            if 1 == (i + 1) % 2:
                temp_prision[i] = -1
        while temp_prision.count(-1) != 0:
            temp_prision.remove(-1)
    print temp_prision
                
    
if __name__ == '__main__':
    number_of_people = int(raw_input("please input the numbers of prisons"))
    josephCircle(number_of_people)

追问

有没有实用一点的比如搜索关键字什么的...这种单纯的数学计算题对我没啥帮助啊 T^T

追答

# -*- coding: utf-8 -*-
import math
import random
import time
def partition(A, start, end):
    x = A[end]
    i = start -  1
    for j in range(start, end):
        if A[j] <= x:
            i = i +  1
            temp = A[i]
            A[i] = A[j]
            A[j] = temp
    temp = A[i + 1]
    A[i +  1] = A[end]
    A[end] = temp
    return i +  1
 
def quicksort(A, start, end):
    if start < end:
        q = partition(A, start, end)
        quicksort(A, start, q -  1)
        quicksort(A, q +  1, end)
 
def random_partition(A, start, end):
    i = random.randint(start, end)
    temp = A[end]
    A[end] = A[i]
    A[i] = temp
    return partition(A, start, end)
 
def random_quicksort(A, start, end):
     if start < end:
        q = random_partition(A, start, end)
        random_quicksort(A, start, q -  1)
        random_quicksort(A, q +  1, end)
     
'''
quick sort
'''

追问

请问这段程序是干嘛的?表示看不懂...

追答

下边不是注释了,快速排序。你看函数的名字也能看出来啊,青年。你不仅编程不行,视野也不是很宽,了解一下计算机算法和数据结构吧。

追问

(⊙o⊙)哦 谢谢啦

温馨提示:答案为网友推荐,仅供参考
相似回答