发牌

// 一个模拟发牌的程序。
#include <stdio.h> #include <stdlib.h> #include <time.h> #define NUM_SUITS 4 #define NUM_RANKS 13 #define TRUE 1 #define FALSE 0 typedef int Bool; main() { Bool in_hand[NUM_SUITS][NUM_RANKS] = {0}; int num_cards, rank, suit; const char rank_code[] = {'2', '3', '4', '5', '6', '7', '8', '9', 't', 'j', 'q', 'k', 'a'}; // const char suit_code[] = {'c', 'd', 'h', 's'}; const char suit_code[] = {'T', 'X', 'M', 'F'}; srand((unsigned) time(NULL)); printf("Enter number of cards in hand: "); scanf("%d", &num_cards); printf("Your hand: "); while (num_cards > 0) { // picks a random suit suit = rand() % NUM_SUITS; // picks a random rank rank = rand() % NUM_RANKS; if (!in_hand[suit][rank]) { in_hand[suit][rank] = TRUE; num_cards--; printf(" %c%c", rank_code[rank], suit_code[suit]); } } printf("\n"); return 0; }

 

posted @ 2013-04-23 23:59  He_LiangLiang  阅读(415)  评论(1编辑  收藏  举报