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