fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. void shuffle(int [ ][13]);
  6. void print_trump(int [ ][13], int*, int*);
  7. int deck[4][13]={{},{}};
  8. int trump_mark[4]={100,200,300,400};
  9. int trump_num[13]={1,2,3,4,5,6,7,8,9,10,11,12,13};
  10.  
  11.  
  12. int main(void){
  13.  
  14. srand(time(NULL));
  15. shuffle(deck);
  16. print_trump(deck,trump_mark,trump_num);
  17.  
  18. return 0;
  19. }
  20.  
  21.  
  22. void shuffle(int deck[][13]){
  23. int r, c, num;
  24.  
  25. for(num = 1; num <= 52; num++){
  26. do{
  27. r = rand()%4;
  28. c = rand()%13;
  29. }while(deck[r][c] != 0);
  30.  
  31. deck[r][c] = num;
  32. }
  33. }
  34.  
  35. void print_trump(int deck[4][13], int*s, int*t){
  36.  
  37. int r, c, num;
  38.  
  39. for(num=1; num <= 52; num++){
  40. for(r = 0; r < 4; r++){
  41. for(c = 0; c < 13; c++){
  42. if(deck[r][c] == num){
  43. printf("%2d:%d-%d\n", num, s[r], t[c]);
  44. }
  45. }
  46. }
  47. }
  48.  
  49. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
 1:300-4
 2:400-12
 3:200-8
 4:300-3
 5:400-8
 6:100-9
 7:300-11
 8:200-2
 9:200-1
10:100-10
11:300-9
12:400-5
13:300-7
14:400-2
15:100-6
16:300-1
17:200-12
18:400-13
19:100-8
20:200-11
21:400-6
22:100-3
23:400-9
24:100-1
25:400-7
26:300-12
27:200-7
28:200-4
29:200-3
30:400-10
31:200-13
32:200-10
33:400-1
34:200-5
35:200-9
36:300-10
37:300-2
38:100-12
39:300-5
40:400-4
41:100-4
42:300-13
43:400-3
44:300-8
45:100-7
46:200-6
47:300-6
48:400-11
49:100-11
50:100-13
51:100-2
52:100-5