0-12表示黑桃 A 1,2,3,... 10,J,Q,K
13-25表示红桃 A 1,2,3,... 10,J,Q,K
26-38表示草花 A 1,2,3,... 10,J,Q,K
39-51表示方块 A 1,2,3,... 10,J,Q,K
52,53表示大小王
#include <stdio.h>
void shuffle(char *porker)
/*将存放数组初始化为1-54*/
for (int i = 0; i < 54; i++)
porker[i] = i;
/*生成随机种子*/
srand(time(NULL));
/*洗牌,生成随机数,两两交换*/
for (int i = 0; i < 54; i++)
int rnd = rand() % 54;
/*指定任意一张牌,与当前牌进行交换*/
int temp = porker[i];
porker[i] = porker[rnd];
porker[rnd] = temp;
void play(char *porker)
for (int i = 0; i < 54; i++)
printf("i=%2d\t", porker[i]);
if ((i + 1) %3==0)
printf("\n");
void bottom(char *porker)
/*定义花色的枚举体*/
enum TYPE{
黑桃,红桃,草花,方块
/*定义几个特殊牌的枚举体*/
enum VALUE{
A=0,J = 11, Q, K
printf("\n=======底牌=========\n");
for (int i = 51; i < 54; i++)
/*大小王特殊处理*/
if (porker[i] == 52) printf("小王");
if (porker[i] == 53) printf("大王");
else{
/*0-12代表红桃的A-1-2-K*/
int type = porker[i] / 13;
int value = porker[i] % 13;
switch (type)
case 黑桃:printf("黑桃"); break;
case 红桃:printf("红桃"); break;
case 草花:printf("草花"); break;
case 方块:printf("方块"); break;
switch (value)
case A:printf("A"); break;
case J:printf("J"); break;
case Q:printf("Q"); break;
case K:printf("K"); break;
default:printf("%d", value); break;
printf("\t");
int main()
/*存放54张扑克的数组*/
char porker[54] = { 0 };
/*洗牌*/
shuffle(porker);
/*出牌*/
play(porker);
/*底牌,3张底牌*/
bottom(porker);
system("pause");
return 0;