
Enter number of cards in hand:52
Your in_hands:D2 S7 D6 D7 H5 C5 Da Hj Dk C4 D8 Sq Cq S2 Hk C6 H3 Sa H4 Dj Ct Hq
S9 Sj H6 C3 Cj D3 H9 D4 St C7 D5 Ck C8 C9 H2 Ha D9 Dt Ht H8 S5 Ca S8 Sk S3 H7 S4
Dq C2 S6
#define NUM_SUITS 4 //花色
#define NUM_RANKS 13 //牌序
char in_hands[NUM_SUITS][NUM_RANKS]={false};
int num_cards=0,rank=0,suit=0;
const char suit_code[]={'C','D','H','S'};
const char rank_code[]={'2','3','4','5','6','7','8','9','t','j','q','k','a'};
srand((unsigned) time(NULL));
printf("Enter number of cards in hand:");scanf("%d",&num_cards);
printf("Your in_hands:");
while(num_cards>0)
{
suit=rand() % NUM_SUITS;
rank=rand() % NUM_RANKS;
if(in_hands[suit][rank]==false) //没发过
{
in_hands[suit][rank]=true;
num_cards--;
printf("%c%c ",suit_code[suit],rank_code[rank]);
}
else
;
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)