2024年3月10日发(作者:)

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 ",[i]);

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

while (getchar()!='0')

{

vote=CreateAVote();

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

printf(" %-2d ",[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<=&&[j]!=x)

j++;

if(j<=)

return j;

else

return 0;

}

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

{

VoteTp v;

int j;

v=*vote;

if((i<1)||(i>+1))

printf(" error number!");

else

{

for(j=;j>=i;j--)

[j+1]=[j];

[i]=x;

=+1;

}

*vote=v;

}

int RightNum(VoteTp vote,VoteTp answervote)

{

int i,k;

k=0;

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

if(SeqLocate(vote,[i])>0)

k++;

return(k);

}

VoteTp CreateAVote()

{

VoteTp vote;

ElemTp k,temp;

int i;

InitializeVote(&vote);

=NN;

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

{

k=random()+1;

SeqInsertVote(&vote,+1,[k]);

temp=[k];

[k]=[];

[]=temp;

=-1;

}

return vote;

}