本文主要是介绍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语言(急急急)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!