for i in f.readlines():
ch=i.replace("\n","")
if ch in super:
pass
else:
people.append(ch)
for i in range(5):
out=[]
super1=random.choice(super)
super.remove(super1)
out.append(super1)
for i in range(4):
normal=random.choice(people)
people.remove(normal)
out.append(normal)
print out[/code]输出如下, 每行为一个队列
age 于 2011-05-30 15:47:46发表:
[i=s] 本帖最后由 age 于 2011-5-31 14:56 编辑 [/i]
原理和前面的一样,
/home/allblue/test/people存放全部选手名称, 一个一行
/home/allblue/test/super存放种子选手名称, 一个一行[code]
#!/bin/bash
#set -x
PEOPLE_SRC="/home/allblue/test/people"
SUPER_SRC="/home/allblue/test/super"
cp $PEOPLE_SRC /tmp
cp $SUPER_SRC /tmp
PEOPLE="/tmp/$(basename $PEOPLE_SRC)"
SUPER="/tmp/$(basename $SUPER_SRC)"
for i in $(cat $SUPER)
do
sed -i "/^$i$/d" $PEOPLE
done
for((i=0;i<5;i++))
do
out=""
super1=$(cat $SUPER | shuf | head -1)
sed -i "/^$super1$/d" $SUPER
out=${out}" "${super1}
for((j=0;j<4;j++))
do
people1=$(cat $PEOPLE | shuf | head -1)
sed -i "/^$people1$/d" $PEOPLE
out=${out}" "${people1}
done
echo $out
done
[/code]输出为[code][allblue@MyLady bash]$ ./people.sh
9 24 11 13 6
16 15 19 14 4
3 17 1 12 18
5 20 10 25 8
22 21 2 7 23[/code]
collboy2009 于 2011-05-29 01:13:21发表:
age 大哥,shell怎么写呢!有点看不懂哦
wangyu 于 2011-05-27 13:37:19发表:
这个,age老大的得使劲顶
age 于 2011-05-27 13:34:52发表:
[i=s] 本帖最后由 age 于 2011-5-27 13:42 编辑 [/i]
用python写了个, 其中/home/allblue/test/allpeople储存了所有选手名单, super是种子选手列表, 而people则为所有非种子选手列表. 为了简化全部用数字代替了:0ww)vu(1
基本原理为: 先从总名单中除去所有种子选手, 得到people列表. 然后针对每个队列, 从super中随机获取一个值, 从people中随机获取4个值, 并从上述二个原队列中删除已取出值, 避免重复引用. 后面的以此类推[code]#! /usr/bin/env python2
#coding=utf-8
import random
f=open("/home/allblue/test/allpeople","r")
super=["1", "3", "8", "12", "15"]
people=[]
for i in f.readlines():
ch=i.replace("\n","")
if ch in super:
pass
else:
people.append(ch)
for i in range(5):
out=[]
super1=random.choice(super)
super.remove(super1)
out.append(super1)
for i in range(4):
normal=random.choice(people)
people.remove(normal)
out.append(normal)
print out[/code]输出如下, 每行为一个队列
['3', '5', '6', '4', '11']
['15', '16', '14', '22', '17']
['8', '9', '2', '20', '19']
['1', '23', '18', '10', '13']
['12', '24', '25', '21', '7']