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