1 #include <stdio.h>
2 #include <time.h>
3
4 int main()
5 {
6
int i,j,k,l;
7
char a[13]={'A','2','3','4','5','6','7','8','9','S','J','Q','K'};
8
char b[4]={'b','r','m','f'};
9
int c[4][13]={0};
10
printf("请输入发牌张数:\n");
11
scanf("%d",&k);
12
while(k<1 || k>52)
13
{
14
printf("输入错误,请重新输入:\n");
15
scanf("%d",&k);
16
}
17
srand(time(0));
18
printf("发牌为:\n");
19
for(i=0;i<k;i++)
20
{
21
int temp = rand();
22
j = temp % 13;
23
l = temp % 4;
24
if(c[l][j]==0)
25
{
26
printf("%c%c ",a[j],b[l]);
27
c[l][j]=1;
28
}
29
else
30
{
31
i--;//相当于循环次数+1
32
}
33
}
34
printf("\n");
35
return 0;
36 }