欢迎来到天天文库
浏览记录
ID:51417707
大小:15.87 KB
页数:6页
时间:2020-03-24
《扑克概率C语言代码.docx》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include"stdio.h"#include"time.h"#include"stdlib.h"#include"math.h"intmain(){inti,j,x,z,y,num,Puke[104],Yi,Er,San,Si,Wu,Liu,Qi,Ba,Jiu,Shi,Gou,PiDan,Laok;intpeople1[26],people2[26],people3[26],people4[26],run;intn,g;intsum1,sum2,sum3,sum4,Gailv;while(1){printf("请输入需要抓牌的局数:(局数越多时间越长,精度(随机度)越高,过高
2、会出现内存错误):");scanf("%d",&n);intxx;xx=n;n=sqrt(n);printf("请输入需要计算抓到几个以上“小二”的概率,范围0-8:");scanf("%d",&g);intstart,stop;start=clock();//程序开始时间Gailv=0;for(z=0;z3、8;Ba=8;Jiu=8;Shi=8;Gou=8;PiDan=8;Laok=8;while(x!=104){num=rand()%13+1;for(j=0;j<1;j++){if(num==1){Yi--;if(Yi>=0){Puke[x]=num;x++;}break;}if(num==2){Er--;if(Er>=0){Puke[x]=num;x++;}break;}if(num==3){San--;if(San>=0){Puke[x]=num;x++;}break;}if(num==4){Si--;if(Si>=0){Puke[x]=num;x++;}break;}if(nu4、m==5){Wu--;if(Wu>=0){Puke[x]=num;x++;}break;}if(num==6){Liu--;if(Liu>=0){Puke[x]=num;x++;}break;}if(num==7){Qi--;if(Qi>=0){Puke[x]=num;x++;}}if(num==8){Ba--;if(Ba>=0){Puke[x]=num;x++;}break;}if(num==9){Jiu--;if(Jiu>=0){Puke[x]=num;x++;}break;}if(num==10){Shi--;if(Shi>=0){Puke[x]=num;x++;}break5、;}if(num==11){Gou--;if(Gou>=0){Puke[x]=num;x++;}break;}if(num==12){PiDan--;if(PiDan>=0){Puke[x]=num;x++;}break;}if(num==13){Laok--;if(Laok>=0){Puke[x]=num;x++;}break;}//生成随机104张牌组}}//牌组循环层run=0;sum1=0;sum2=0;sum3=0;sum4=0;for(j=0;j<=100;j=j+4){people1[run]=Puke[j];if(Puke[j]==2){sum1++;}people6、2[run]=Puke[j+1];if(Puke[j+1]==2){sum2++;}people3[run]=Puke[j+2];if(Puke[j+2]==2){sum3++;}people4[run]=Puke[j+3];if(Puke[j+3]==2){sum4++;}run++;}//发牌循环层if(sum1>=g7、8、sum2>=g9、10、sum3>=g11、12、sum4>g){Gailv++;}//printf("四个玩家有人抓到8小二的次数为%d",Gailv);/*printf("玩家A获得牌型:");for(j=0;j<26;j++){printf("%2d",p13、eople1[j]);}printf("玩家B获得牌型:");for(j=0;j<26;j++){printf("%2d",people2[j]);}printf("玩家C获得牌型:");for(j=0;j<26;j++){printf("%2d",people3[j]);}printf("玩家D获得牌型:");for(j=0;j<26;j++){printf("%2d",people4[j]);}*/}//抓牌轮数循环层}printf("四个
3、8;Ba=8;Jiu=8;Shi=8;Gou=8;PiDan=8;Laok=8;while(x!=104){num=rand()%13+1;for(j=0;j<1;j++){if(num==1){Yi--;if(Yi>=0){Puke[x]=num;x++;}break;}if(num==2){Er--;if(Er>=0){Puke[x]=num;x++;}break;}if(num==3){San--;if(San>=0){Puke[x]=num;x++;}break;}if(num==4){Si--;if(Si>=0){Puke[x]=num;x++;}break;}if(nu
4、m==5){Wu--;if(Wu>=0){Puke[x]=num;x++;}break;}if(num==6){Liu--;if(Liu>=0){Puke[x]=num;x++;}break;}if(num==7){Qi--;if(Qi>=0){Puke[x]=num;x++;}}if(num==8){Ba--;if(Ba>=0){Puke[x]=num;x++;}break;}if(num==9){Jiu--;if(Jiu>=0){Puke[x]=num;x++;}break;}if(num==10){Shi--;if(Shi>=0){Puke[x]=num;x++;}break
5、;}if(num==11){Gou--;if(Gou>=0){Puke[x]=num;x++;}break;}if(num==12){PiDan--;if(PiDan>=0){Puke[x]=num;x++;}break;}if(num==13){Laok--;if(Laok>=0){Puke[x]=num;x++;}break;}//生成随机104张牌组}}//牌组循环层run=0;sum1=0;sum2=0;sum3=0;sum4=0;for(j=0;j<=100;j=j+4){people1[run]=Puke[j];if(Puke[j]==2){sum1++;}people
6、2[run]=Puke[j+1];if(Puke[j+1]==2){sum2++;}people3[run]=Puke[j+2];if(Puke[j+2]==2){sum3++;}people4[run]=Puke[j+3];if(Puke[j+3]==2){sum4++;}run++;}//发牌循环层if(sum1>=g
7、
8、sum2>=g
9、
10、sum3>=g
11、
12、sum4>g){Gailv++;}//printf("四个玩家有人抓到8小二的次数为%d",Gailv);/*printf("玩家A获得牌型:");for(j=0;j<26;j++){printf("%2d",p
13、eople1[j]);}printf("玩家B获得牌型:");for(j=0;j<26;j++){printf("%2d",people2[j]);}printf("玩家C获得牌型:");for(j=0;j<26;j++){printf("%2d",people3[j]);}printf("玩家D获得牌型:");for(j=0;j<26;j++){printf("%2d",people4[j]);}*/}//抓牌轮数循环层}printf("四个
此文档下载收益归作者所有