----------------解决方案--------------------------------------------------------
洗牌可以用随机数嘛。不知道你要图形界面的还是只用数字模拟
----------------解决方案--------------------------------------------------------
可以建立一个4*13的数组,行代表四种花色,列代表13张牌
----------------解决方案--------------------------------------------------------
随机洗牌怎么处理的
----------------解决方案--------------------------------------------------------
一个随机点数(1~K的),一个随机花色(桃杏梅方),然后判断一下这张牌是否已经存在,如果存在就再随机一次
----------------解决方案--------------------------------------------------------
问题已解决: #include<stdio.h> #include<stdlib.h> #include<time.h> void main() { struct pk { int hua; char dian; }p[52];
int huase[4]={6,3,5,4}; char num[13]={'A','2','3','4','5','6','7','8','9','0','J','Q','K'};
int i,j,k,temp1,temp2;
for(i=0;i<4;i++) { for(j=0;j<13;j++) { p[(j+13*i)].hua=huase[i]; p[(j+13*i)].dian=num[j]; } } printf("未洗牌之前:\n"); for(i=0;i<52;i++) { printf("%c%c ",p[i].hua,p[i].dian); if((i+1)%13==0) printf("\n"); } printf("\n");
//随机洗牌 srand((unsigned)time(NULL)); for(i=0;i<52;i++) { k=rand()%(52-i); temp1=p[k].hua; p[k].hua=p[51-i].hua; p[51-i].hua=temp1;
temp2=p[k].dian; p[k].dian=p[51-i].dian; p[51-i].dian=temp2; } printf("随机洗牌之后:\n"); for(i=0;i<52;i++) { printf("%c%c ",p[i].hua,p[i].dian); if((i+1)%13==0) printf("\n"); } printf("\n"); }
----------------解决方案--------------------------------------------------------
好厉害,我用指针写了一下,输出不出来...大家帮我看看,我只写了一小段,随机部分没写
#include<stdio.h>
void main()
{
char *p1[20],*p2[20];
char a[13]={'A','1','2','3','4','5','6','7','8','9','0','Q','K'};
int b[4]={6,3,4,5};
int i,j;
for (i=0;i<4;i++)
{
for(j=0;j<13;j++)
{
*p1[j+13*i]=b[i];
*p2[j+13*i]=a[j];
}
}
for(i=0;i<4;i++)
for(j=0;j<13;j++)
printf("%c%c",p1,p2);
}
谢谢,帮帮小弟弟
----------------解决方案--------------------------------------------------------
问题已解决: #include<stdio.h> #include<stdlib.h> #include<time.h> void main() {..................
你的这个程序我复制到TC中运行不了,有错误哦``1
----------------解决方案--------------------------------------------------------
这是随机发牌的一段代码,试试看。欢迎大家提意见! #include<graphics.h> #include<time.h> void main(void) { int p; int gdriver,gmode; gd=DETECT; initgraph(&gd,&gm,"d:\\tc"); srand(time(NULL)); p=random(13)+1; if(p==11)
{ setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"J"); outtextxy(90,125,"J"); }
else if(p==12) {setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"Q"); outtextxy(90,125,"Q"); }
else if(p==13) {setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"K"); outtextxy(90,125,"K"); }
else if(p==1) {setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"A"); outtextxy(90,125,"A"); }
else if(p==2) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"2"); outtextxy(90,125,"2"); }
else if(p==3) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"3"); outtextxy(90,125,"3"); } else if(p==4) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"4"); outtextxy(90,125,"4"); } else if(p==5) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"5"); outtextxy(90,125,"5"); }
else if(p==6) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"6"); outtextxy(90,125,"6"); } else if(p==7) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"7"); outtextxy(90,125,"7"); }
else if(p==8) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"8"); outtextxy(90,125,"8"); } else if(p==9) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"9"); outtextxy(90,125,"9"); } else if(p==10) { setcolor(1); settextstyle(1,0,3); outtextxy(25,15,"10"); outtextxy(90,125,"10");
}
}
----------------解决方案--------------------------------------------------------
/*弄错了一点,下面才是随机发牌*/ #include<graphics.h> #include<time.h> #include<stdli.h> void main(void) { int p; int gdriver,gmode; int gd,gm; gd=DETECT; initgraph(&gd,&gm,"d:\\tc"); srand(time(NULL)); p=random(13)+1; if(p==11)
{ setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"J"); outtextxy(90,125,"J"); }
else if(p==12) {setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"Q"); outtextxy(90,125,"Q"); }
else if(p==13) {setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"K"); outtextxy(90,125,"K"); }
else if(p==1) {setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"A"); outtextxy(90,125,"A"); }
else if(p==2) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"2"); outtextxy(90,125,"2"); }
else if(p==3) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"3"); outtextxy(90,125,"3"); } else if(p==4) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"4"); outtextxy(90,125,"4"); } else if(p==5) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"5"); outtextxy(90,125,"5"); }
else if(p==6) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"6"); outtextxy(90,125,"6"); } else if(p==7) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"7"); outtextxy(90,125,"7"); }
else if(p==8) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"8"); outtextxy(90,125,"8"); } else if(p==9) { setcolor(1); settextstyle(1,0,4); outtextxy(25,15,"9"); outtextxy(90,125,"9"); } else if(p==10) { setcolor(1); settextstyle(1,0,3); outtextxy(25,15,"10"); outtextxy(90,125,"10");
}
}
----------------解决方案--------------------------------------------------------