[cpp]
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
struct CARD
{
char suit[10];//花色
char face[10];//牌面
};
void Deal(struct CARD *wCard);
void Shuffle(struct CARD *wCard);
void FillCard(struct CARD wCard[],char *wFace[],char *wSuit[]);
int main()
{
char *suit[]={"Spades","Hearts","Clubs","Diamonds"};//黑 紅 梅花 方片
char *face[]={"A","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};
//int i;
struct CARD card[52];
srand(time(NULL));
FillCard(card,face,suit);
Shuffle(card);
Deal(card);
}
//洗牌過程
void FillCard(struct CARD wCard[],char *wFace[],char *wSuit[])
{
int i;
for (i=0;i<52;i++)
{
strcpy(wCard[i].suit,wSuit[i/13]);
strcpy(wCard[i].face,wFace[i%13]);
}
}
//發牌過程
void Shuffle(struct CARD *wCard)
{
int i,j;
struct CARD temp;
for (i=0;i<52;i++)
{
j=rand()%52;
temp=wCard[i];
wCard[i]=wCard[j];
wCard[j]=temp;
}
}
//輸出發牌結果
void Deal(struct CARD *wCard)
{
int i;
for (i=0;i<52;i++)
{
printf("%2d:%10s%10s\n",i+1,wCard[i].suit,wCard[i].face);
}
}