问题已解决: #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<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");
}
}