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