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