随机发牌
求助 随机发牌 52张4个人 要带花色
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int a[52] = {0}; int b[4][13] = {0}; int temp, i, j; srand(time(0)); for (i = 0;i < 52;++i) { temp = rand() % 52; if (a[temp]) { --i;continue; } a[temp] = 1; b[i%4][i/4] = temp; } for (i = 0;i < 4;++i, puts("")) { for (j = 0;j < 13;++j) { switch(b[i][j] % 4) { case 0: printf("红心 "); break; case 1: printf("方块 "); break; case 2: printf("黑桃 "); break; default: printf("梅花 "); } switch(b[i][j] / 4) { case 1: printf("A\t"); break; case 11: printf("J\t"); break; case 12: printf("Q\t"); break; case 0: printf("K\t"); break; default: printf("%d\t", b[i][j] / 4); } } } return 0; }