阅读上一个主题 :: 阅读下一个主题 |
作者 |
谁能看出来产生陪审团的程序是错的? |
 |
随便
加入时间: 2004/02/14 文章: 24019
经验值: 64
|
|
|
作者:随便 在 众议院 发贴, 来自 http://www.hjclub.org
这个错误,导致选取陪审员,机会不公平。俺二十秒内就看出
了错误,这里高手甚多,几秒钟内能看出错误的多的很。
=====================================================
附:准陪审团名单排序生成程序,运行于xp,需vc6
#include
#include
// We have only 20 candidates
#define POOL_SIZE 20
// seed is the result of NEW JERSEY LOTTERY PICK 4
// in the evening of 20 Oct. 2003. We hard-code it
// here.
#define seed 9968
#define NAMEFILE "c:\\names.txt"
#define OUTPUT "c:\\output.txt"
#define MAX_NAME_SIZE 40
int main ( )
{
FILE * fp , * fpo ;
int i ,j ,n ;// seed is a constant
wchar_t * names [ POOL_SIZE ] , * jury [ POOL_SIZE ] ;
//Allocate the memory
for ( i =0 ;i
names [ i ] = new wchar_t [ MAX_NAME_SIZE ] ;
//open the name file
fp = fopen ( NAMEFILE , "r" ) ;
fpo = fopen ( OUTPUT , "w" ) ;
if ( ! fp || ! fpo ) {
printf ( "Files open error!\n" ) ;
exit ( 0 ) ;
}
//Read the names into the array
//NAMEFILE is saved in a format of one name per line
i =0 ;
while ( ! feof ( fp ) &&i < POOL_SIZE )
fwscanf ( fp ,L"%S" ,names [ i ++ ] ) ;
fclose ( fp ) ;
//test
for ( i =0 ;i
fwprintf ( fpo ,L"%S\n" ,names [ i ] );
fwprintf ( fpo ,L"\n" );
//Get the seed
//Don't need to read seed --- it's hard-coded
//printf("Please input the seed:");
//scanf("%i", &seed);
//Set the seed
srand ( seed ) ;
//Generate the order
//we will get one name in each iteration
//n is the number of names left in pool
//i is the order of jury candidates
for ( i =0 ,n =POOL_SIZE ;n >0 ;n -- ,i ++ ) {
j = rand ( ) %n ;
jury [ i ] =names [ j ] ;
//replace the chosen name by the last available name in the arry
//so that it will not be selected again.
names [ j ] =names [ n -1 ] ;
}
//print out the result (海纳百川 www.hjclub.com)
for ( i =0 ;i
fwprintf ( fpo ,L"%i %S\n" ,i + 1 ,jury [ i ] ) ;
fclose ( fpo ) ;
return 0 ;
}
作者:随便 在 众议院 发贴, 来自 http://www.hjclub.org |
|
|
返回顶端 |
|
 |
|
|
|
您不能在本论坛发表新主题 您不能在本论坛回复主题 您不能在本论坛编辑自己的文章 您不能在本论坛删除自己的文章 您不能在本论坛发表投票 您不能在这个论坛添加附件 您不能在这个论坛下载文件
|
based on phpbb, All rights reserved.
|