望远
#include
#include
#include
typedef struct{
char *color;
char *number;
}Card;
void shuffle(Card cards[][13],int n,int m)
{
srand(time(0));
Card card[52];
Card tempCard;
int i,j;
for(i=0;i
{
for(j=0;j
{
card[i*13+j]=cards[i][j];
}
}
for(i=0;i<52;i++)
{
int temp=rand()%(52-i)+i;
tempCard=card[i];
card[i]=card[temp];
card[temp]=tempCard;
}
for(i=0;i<4;i++)
{
for(j=0;j<13;j++)
{
cards[i][j]=card[i*13+j];
}
}
}
void main()
{
char colors[4][10]={"红心","梅花","方块","黑桃"};
char number[][4]={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
Card cards[4][13];//共52张牌(不考虑大小王)
int i,j;
for(i=0;i<=3;i++)
{
for(j=0;j<=12;j++)
{
cards[i][j].color=colors[i];
cards[i][j].number=number[j];
}
}
printf("洗牌前:\n");
for(i=0;i<=3;i++)
{
for(j=0;j<=12;j++)
{
printf("%s%s ",cards[i][j].color,cards[i][j].number);
}
printf("\n");
}
shuffle(cards,4,13);
printf("洗牌后:\n");
for(i=0;i<=3;i++)
{
for(j=0;j<=12;j++)
{
printf("%s%s ",cards[i][j].color,cards[i][j].number);
}
printf("\n");
}
}ps:我这里有一个用数组做的,希望对你有帮助。