admin 管理员组

文章数量: 887007

c语言随机发牌1到13不包括花色,c语言(急急急)

#include 

#include 

#include 

#include 

#define WITH_JOKER 0 // 是否包含大王、小王,非0为包含,0为不包含

#define COLUMN 4    // 发牌的列(堆)数

int main()

{

int total;

total=(WITH_JOKER)?54:52;

char* kind[]={"Spades","Hearts","Diamonds","Clubs"};

char* value[]={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};

int* a=(int*)malloc(total*sizeof(int));

int seed=(unsigned)time(NULL);

srand(seed);

for(int i=0;i

{

a[i]=rand()%total;

for(int j=0;j

{

while(a[j]==a[i])

{

a[i]=rand()%total;

j=0;

}

}

}

for(i=0;i

{

switch(a[i])

{

case 52:

{

printf("     Joker A");

}

break;

case 53:

{

printf("     Joker B");

}

break;

default:

{

printf("%10s%2s",kind[a[i]/13],value[a[i]%13]);

}

break;

}

if((i+1)%COLUMN==0)

printf("\n");

}

printf("\n");

return 0;

}

本文标签: c语言随机发牌1到13不包括花色 c语言(急急急)