自动发牌:一副扑克有52张牌,打桥牌的时候将牌分给四个人。请设计个程序完成自动发牌工作
2个回答
展开全部
vc写的!
void CQiaopaiDlg::OnFa()
{
// TODO: Add your control notification handler code here
this->m_strj="";
this->m_strn="";
this->m_strx="";
this->m_strs="";
UpdateData(false);
srand( (unsigned)time( NULL ) );//以时间为随机种子
char b[3];
int i,y=0,m,j=0,n=0,x=0,s=0;
char se[4];
for(i=1;i<53;i++){
ji:
m=rand()%4;
y=i%4;
if(y==0)
strcpy(se,"红");
else if(y==1)
strcpy(se,"黑");
else if(y==2)
strcpy(se,"方");
else
strcpy(se,"梅");
if(m==0)
{
if(j>=13)
goto ji;
m=i%13+1;
j=j+1;
itoa(m,b,10);
m_strj=m_strj + " " + se+b;
}
else if(m==1)
{
if(n>=13)
goto ji;
n=n+1;
m=i%13+1;
itoa(m,b,10);
m_strn=m_strn + " " + se+b;
}
else if(m==2)
{
if(x>=13)
goto ji;
x=x+1;
m=i%13+1;
itoa(m,b,10);
m_strx=m_strx + " " + se+b;
}
else
{
if(s>=13)
goto ji;
s=s+1;
m=i%13+1;
itoa(m,b,10);
m_strs=m_strs + " " + se+b;
}
}
UpdateData(false);
}
void CQiaopaiDlg::OnFa()
{
// TODO: Add your control notification handler code here
this->m_strj="";
this->m_strn="";
this->m_strx="";
this->m_strs="";
UpdateData(false);
srand( (unsigned)time( NULL ) );//以时间为随机种子
char b[3];
int i,y=0,m,j=0,n=0,x=0,s=0;
char se[4];
for(i=1;i<53;i++){
ji:
m=rand()%4;
y=i%4;
if(y==0)
strcpy(se,"红");
else if(y==1)
strcpy(se,"黑");
else if(y==2)
strcpy(se,"方");
else
strcpy(se,"梅");
if(m==0)
{
if(j>=13)
goto ji;
m=i%13+1;
j=j+1;
itoa(m,b,10);
m_strj=m_strj + " " + se+b;
}
else if(m==1)
{
if(n>=13)
goto ji;
n=n+1;
m=i%13+1;
itoa(m,b,10);
m_strn=m_strn + " " + se+b;
}
else if(m==2)
{
if(x>=13)
goto ji;
x=x+1;
m=i%13+1;
itoa(m,b,10);
m_strx=m_strx + " " + se+b;
}
else
{
if(s>=13)
goto ji;
s=s+1;
m=i%13+1;
itoa(m,b,10);
m_strs=m_strs + " " + se+b;
}
}
UpdateData(false);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询