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