体育彩票的模拟生成和兑奖c程序

王朝c/c++·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#include <math.h>

#define MM 7

#define NN 36

typedef int ElemTp;

typedef struct

{

ElemTp elem[MM+1];

int len;

} VoteTp;

typedef struct

{

ElemTp elem[NN+1];

int len;

} SourceTp;

SourceTp source;

InitializeVote(VoteTp *vote);

InitializeSource(SourceTp *source);

void SeqInsertVote(VoteTp *vote,int i,ElemTp x);

int SeqLocate(VoteTp v,ElemTp x);

VoteTp CreateAVote();

int RightNum(VoteTp vote,VoteTp answervote);

main()

{

VoteTp vote;

VoteTp answervote;

int k,i;

randomize();

InitializeSource(&source);

answervote=CreateAVote();

printf("\nPress Any Key to Continue ,0 to exit !");

printf("\n Answer Numbers: ");

for (i=1;i<=MM;i++)

printf("%3d ",answervote.elem[i]);

printf("\n Your Vote Numbers ---->>Right Numbers \n");

while (getchar()!='0')

{

vote=CreateAVote();

for (i=1;i<=MM;i++)

printf(" %-2d ",vote.elem[i]);

k=RightNum(vote,answervote);

printf(" ---->> %d \n",k);

}

}

InitializeVote(VoteTp *vote)

{

vote->len=0;

}

InitializeSource(SourceTp *Source)

{

int i;

for(i=1;i<=NN;i++)

Source->elem[i]=i;

Source->len=NN;

}

int SeqLocate(VoteTp v,ElemTp x)

{

int j=1;

while(j<=v.len&&v.elem[j]!=x)

j++;

if(j<=v.len)

return j;

else

return 0;

}

void SeqInsertVote(VoteTp *vote,int i,ElemTp x)

{

VoteTp v;

int j;

v=*vote;

if((i<1)||(i>v.len+1))

printf(" error number!");

else

{

for(j=v.len;j>=i;j--)

v.elem[j+1]=v.elem[j];

v.elem[i]=x;

v.len=v.len+1;

}

*vote=v;

}

int RightNum(VoteTp vote,VoteTp answervote)

{

int i,k;

k=0;

for (i=1;i<=MM;i++)

if(SeqLocate(vote,answervote.elem[i])>0)

k++;

return(k);

}

VoteTp CreateAVote()

{

VoteTp vote;

ElemTp k,temp;

int i;

InitializeVote(&vote);

source.len=NN;

for(i=1;i<=MM;i++)

{

k=random(source.len)+1;

SeqInsertVote(&vote,vote.len+1,source.elem[k]);

temp=source.elem[k];

source.elem[k]=source.elem[source.len];

source.elem[source.len]=temp;

source.len=source.len-1;

}

return vote;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航