fork download
  1. #include <stdio.h>
  2. #include<stdlib.h>
  3. #include<time.h>
  4.  
  5. int running(int var1)
  6. {
  7. if (var1 == 0) //20%확률(이김) 일때 1리턴
  8. return 1;
  9. else
  10. return 0; //80%확률(짐) 일때 0리턴
  11. }
  12.  
  13. int win(int money, int var2)
  14. {
  15. if (var2 == 0) //1등 3배
  16. return money * 3;
  17. else if (var2 == 1) //2등 2배
  18. return money * 2;
  19. }
  20.  
  21. int lose(int money)
  22. {
  23. return money;
  24. }
  25.  
  26. int game(int var1, int var2, int* money, int betting)
  27. {
  28. int res;
  29. res = running(var1);
  30. if (res == 1)
  31. {
  32. if (var2 == 0)
  33. {
  34. *money = *money + win(betting, var2);
  35. printf("money : %10d \t betting: %10d Win*3\n", *money, betting);
  36. return 0;
  37. }
  38. if (var2 == 1)
  39. {
  40. *money = *money + win(betting, var2);
  41. printf("money : %10d \t betting: %10d Win*2\n", *money, betting);
  42. return 0;
  43. }
  44. //*money = *money + win(betting, var2);
  45. //printf("money : %10d \t betting: %10d Win\n", *money, betting);
  46. //return 0;
  47. }
  48. else if (res == 0)
  49. {
  50. *money = *money - lose(betting);
  51. printf("money : %10d \t betting: %10d Lose\n", *money, betting);
  52. return 1;
  53. }
  54. return money;
  55.  
  56. }
  57. int main(void)
  58. {
  59. int i = 0, var1, var2, res, end;
  60. static int cnt = 0;
  61. static int cnt2 = 0;
  62. int money = 100000000; int betting = 10000;
  63.  
  64. var1 = rand() % 5;
  65. var2 = rand() % 2;
  66. srand(time(NULL));
  67.  
  68.  
  69.  
  70.  
  71. ////for (i = 0; i < 20; i++)
  72. ////{
  73. //// var1 = rand() % 5;
  74. //// var2 = rand() % 2;
  75. //// printf("%d %d\n", var1, var2);
  76. ////}rand값확인 유효값확인완료
  77. //
  78. ////money=game(var1, var2, &money, betting);
  79. ////printf("money : %4d\n", money);
  80. //for (i = 0; i < 20; i++)
  81. //{
  82. // var1 = rand() % 5;
  83. // var2 = rand() % 2;
  84. // game(var1, var2, &money, betting);
  85. // printf("money : %4d\n", money);
  86. //}
  87. ////1회게임완료
  88.  
  89.  
  90. while (1)
  91. {
  92. var1 = rand() % 5;
  93. var2 = rand() % 2;
  94. betting = 10000;
  95. end = game(var1, var2, &money, betting); cnt++;
  96.  
  97. if (end == 1) //패했을시
  98. {
  99.  
  100. while (1) //이길때까지 반복
  101. {
  102. betting *= 2;
  103. var1 = rand() % 5;
  104. var2 = rand() % 2;
  105. end = game(var1, var2, &money, betting); cnt++; cnt2++;
  106.  
  107. if (end == 0)
  108. break;
  109.  
  110. if (money < 0)
  111. {
  112. printf("bankrupt!!!");
  113. printf("count : %d, continuous cnt : %d\n", cnt, cnt2 + 1);
  114. return 0;
  115. }
  116. }
  117. }
  118.  
  119. if (money < 0)
  120. {
  121. printf("bankrupt!!!");
  122. printf("count : %d, continuous cnt : %d\n", cnt, cnt2 + 1);
  123. return 0;
  124. }
  125. printf("count : %d, continuous cnt : %d\n", cnt, cnt2 + 1);
  126. cnt2 = 0;
  127. }
  128. return 0;
  129. }
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
money :  100030000 	 betting:      10000 Win*3
count : 1, continuous cnt : 1
money :  100020000 	 betting:      10000 Lose
money :  100000000 	 betting:      20000 Lose
money :   99960000 	 betting:      40000 Lose
money :  100200000 	 betting:      80000 Win*3
count : 5, continuous cnt : 4
money :  100190000 	 betting:      10000 Lose
money :  100250000 	 betting:      20000 Win*3
count : 7, continuous cnt : 2
money :  100240000 	 betting:      10000 Lose
money :  100220000 	 betting:      20000 Lose
money :  100180000 	 betting:      40000 Lose
money :  100100000 	 betting:      80000 Lose
money :   99940000 	 betting:     160000 Lose
money :   99620000 	 betting:     320000 Lose
money :   98980000 	 betting:     640000 Lose
money :  101540000 	 betting:    1280000 Win*2
count : 15, continuous cnt : 8
money :  101530000 	 betting:      10000 Lose
money :  101510000 	 betting:      20000 Lose
money :  101590000 	 betting:      40000 Win*2
count : 18, continuous cnt : 3
money :  101580000 	 betting:      10000 Lose
money :  101620000 	 betting:      20000 Win*2
count : 20, continuous cnt : 2
money :  101610000 	 betting:      10000 Lose
money :  101590000 	 betting:      20000 Lose
money :  101710000 	 betting:      40000 Win*3
count : 23, continuous cnt : 3
money :  101700000 	 betting:      10000 Lose
money :  101740000 	 betting:      20000 Win*2
count : 25, continuous cnt : 2
money :  101730000 	 betting:      10000 Lose
money :  101710000 	 betting:      20000 Lose
money :  101670000 	 betting:      40000 Lose
money :  101590000 	 betting:      80000 Lose
money :  101430000 	 betting:     160000 Lose
money :  102070000 	 betting:     320000 Win*2
count : 31, continuous cnt : 6
money :  102060000 	 betting:      10000 Lose
money :  102040000 	 betting:      20000 Lose
money :  102000000 	 betting:      40000 Lose
money :  102240000 	 betting:      80000 Win*3
count : 35, continuous cnt : 4
money :  102230000 	 betting:      10000 Lose
money :  102210000 	 betting:      20000 Lose
money :  102290000 	 betting:      40000 Win*2
count : 38, continuous cnt : 3
money :  102280000 	 betting:      10000 Lose
money :  102340000 	 betting:      20000 Win*3
count : 40, continuous cnt : 2
money :  102330000 	 betting:      10000 Lose
money :  102390000 	 betting:      20000 Win*3
count : 42, continuous cnt : 2
money :  102380000 	 betting:      10000 Lose
money :  102360000 	 betting:      20000 Lose
money :  102320000 	 betting:      40000 Lose
money :  102240000 	 betting:      80000 Lose
money :  102560000 	 betting:     160000 Win*2
count : 47, continuous cnt : 5
money :  102550000 	 betting:      10000 Lose
money :  102590000 	 betting:      20000 Win*2
count : 49, continuous cnt : 2
money :  102580000 	 betting:      10000 Lose
money :  102560000 	 betting:      20000 Lose
money :  102640000 	 betting:      40000 Win*2
count : 52, continuous cnt : 3
money :  102630000 	 betting:      10000 Lose
money :  102610000 	 betting:      20000 Lose
money :  102570000 	 betting:      40000 Lose
money :  102490000 	 betting:      80000 Lose
money :  102330000 	 betting:     160000 Lose
money :  102010000 	 betting:     320000 Lose
money :  101370000 	 betting:     640000 Lose
money :  100090000 	 betting:    1280000 Lose
money :   97530000 	 betting:    2560000 Lose
money :   92410000 	 betting:    5120000 Lose
money :  123130000 	 betting:   10240000 Win*3
count : 63, continuous cnt : 11
money :  123120000 	 betting:      10000 Lose
money :  123160000 	 betting:      20000 Win*2
count : 65, continuous cnt : 2
money :  123150000 	 betting:      10000 Lose
money :  123130000 	 betting:      20000 Lose
money :  123210000 	 betting:      40000 Win*2
count : 68, continuous cnt : 3
money :  123200000 	 betting:      10000 Lose
money :  123180000 	 betting:      20000 Lose
money :  123260000 	 betting:      40000 Win*2
count : 71, continuous cnt : 3
money :  123250000 	 betting:      10000 Lose
money :  123230000 	 betting:      20000 Lose
money :  123190000 	 betting:      40000 Lose
money :  123110000 	 betting:      80000 Lose
money :  122950000 	 betting:     160000 Lose
money :  122630000 	 betting:     320000 Lose
money :  121990000 	 betting:     640000 Lose
money :  120710000 	 betting:    1280000 Lose
money :  118150000 	 betting:    2560000 Lose
money :  113030000 	 betting:    5120000 Lose
money :  102790000 	 betting:   10240000 Lose
money :   82310000 	 betting:   20480000 Lose
money :   41350000 	 betting:   40960000 Lose
money :  -40570000 	 betting:   81920000 Lose
bankrupt!!!count : 85, continuous cnt : 14