typedef unsigned char Card;
// 扑克元素数据
const Card* cardTbl =
"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d"
"\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d"
"\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d"
"\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d";
// 洗牌
void shuffle(int need, Card handTbl[], Card left[], int cnt)
{
while (need-- > 0){
int idx = rand() % cnt;
handTbl[need] = left[idx];
left[idx] = left[--cnt];
}
}
// 显示
void showCard(int cnt, Card tbl[])
{
const char* flower = "♦♥♣♠";
while (cnt-- > 0){
int n = tbl[cnt] % 16;
int f = tbl[cnt] / 16;
printf("%d%s", n, flower[f *2]);
}
}
void main()
{
// 原始排堆
Card left[52];
memcpy(left, cardTbl, 52);
int leftCnt = 52;
// 洗发
Card play[2][5];
leftCnt = shuffle(5, play[0], cardTbl, leftCnt);
leftCnt = shuffle(5, play[1], cardTbl, leftCnt);
// 显示
showCard(5, play[0]);
showCard(5, play[1]);
}