下面实现给你参考,显示前13张牌
#include
#include
#include
#define MAXP 52
#define MAXT 14
#define MAXF 4
#define MAXD 13
typedef struct _p
{
int p1;
int p2;
}PT,*P;
void init(P p[MAXP])
{
int i;
for(i=0;i
p[i]->p1 = i % MAXT;
p[i]->p2 = i % MAXF;
}
}
void shuffle(P p[MAXP])
{
int i,k;
PT t[MAXP];
time_t ti;
srand((unsigned) time(&ti));
for(i=0;i
k=(int)(((double) rand()/((double) RAND_MAX+1))*(52));
if(-1==t[k].p1)
{
t[k]=*(p[i]);
}
else
{
while(-1!=t[k].p1)
{
(k==(MAXP-1))?k=0:k++;
}
t[k]=*(p[i]);
}
}
for(i=0;i
void display(P p[MAXP])
{
char* A[14]={"A","1","2","3","4","5","6","7","8","9","10","J","Q","K"};
char* B[4]={"C","D","H","S"};
int k;
for(k=0;k
printf("%s%s ",A[p[k]->p1],B[p[k]->p2]);
}
printf("\n");
}
int main(char* a,char** b)
{
int k;
P p[MAXP];
for(k=0;k
p[k]=(P)malloc(8);
}
init(p);
shuffle(p);
display(p);
for(k=0;k
free(p[k]);
}
return 0;
}
英文的呀!看不懂