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

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

來源:互聯網  2006-01-10 01:19:30  評論

#include

#include

#include

#include

#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;

}

#include

#include

#include

#include

#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;

}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
青岛大学2018秋《C语言程序设计》期末模拟练习是为了考察学生对C语言程序设计的掌握程度和运用能力而设计的一次模拟考试。这次练习将涵盖C语言的基础知识、语法规则以及常用的编程思想和技巧。 在这次练习中,学生可能会遇到一系列的选择题和编程题。选择题主要考查学生对C语言知识点的理解和记忆,例如变量类型、运算符、控制语句等内容。编程题则要求学生根据题目要求,用C语言编写程序,解决特定的问题。 这次模拟练习的目的是使学生在考试前对自己的学习情况进行自测和巩固,帮助学生熟悉考试形式和要求,提高其应试能力和自信心。练习中的题目可能会涉及到实际应用场景,如计算器的实现、数组排序、字符串处理等等,通过解决这些实际问题,学生可以锻炼解决问题的能力和编程思维。 为了顺利完成练习,学生应提前复习和总结课堂所学知识,掌握C语言的基本概念和常用的编程技巧。平时应多进行编程实践,积累解题经验和编程技巧。同时,要加强对问题的分析和思考能力,培养自学能力和独立解决问题的能力。 总结起来,青岛大学2018秋《C语言程序设计》期末模拟练习是考察学生对C语言的掌握和应用能力的一次考试。通过这次模拟练习,学生可以对自己的学习情况进行自测和巩固,提高应试能力。为了顺利完成练习,学生应提前复习和总结课堂所学知识,加强编程实践,培养问题解决和思考能力。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值