#include <stdio.h> #include<stdlib.h> #include<time.h> int running(int var1) { if (var1 == 0) //20%확률(이김) 일때 1리턴 return 1; else return 0; //80%확률(짐) 일때 0리턴 } int win(int money, int var2) { if (var2 == 0) //1등 3배 return money * 3; else if (var2 == 1) //2등 2배 return money * 2; } int lose(int money) { return money; } int game(int var1, int var2, int* money, int betting) { int res; res = running(var1); if (res == 1) { if (var2 == 0) { *money = *money + win(betting, var2); printf("money : %10d \t betting: %10d Win*3\n", *money, betting); return 0; } if (var2 == 1) { *money = *money + win(betting, var2); printf("money : %10d \t betting: %10d Win*2\n", *money, betting); return 0; } //*money = *money + win(betting, var2); //printf("money : %10d \t betting: %10d Win\n", *money, betting); //return 0; } else if (res == 0) { *money = *money - lose(betting); printf("money : %10d \t betting: %10d Lose\n", *money, betting); return 1; } return money; } int main(void) { int i = 0, var1, var2, res, end; static int cnt = 0; static int cnt2 = 0; int money = 1000000000; int betting = 10000; var1 = rand() % 5; var2 = rand() % 2; srand(time(NULL)); ////for (i = 0; i < 20; i++) ////{ //// var1 = rand() % 5; //// var2 = rand() % 2; //// printf("%d %d\n", var1, var2); ////}rand값확인 유효값확인완료 // ////money=game(var1, var2, &money, betting); ////printf("money : %4d\n", money); //for (i = 0; i < 20; i++) //{ // var1 = rand() % 5; // var2 = rand() % 2; // game(var1, var2, &money, betting); // printf("money : %4d\n", money); //} ////1회게임완료 while (1) { var1 = rand() % 5; var2 = rand() % 2; betting = 10000; end = game(var1, var2, &money, betting); cnt++; if (end == 1) //패했을시 { while (1) //이길때까지 반복 { betting *= 2; var1 = rand() % 5; var2 = rand() % 2; end = game(var1, var2, &money, betting); cnt++; cnt2++; if (end == 0) break; if (money < 0) { printf("bankrupt!!!"); printf("count : %d, continuous cnt : %d\n", cnt, cnt2 + 1); return 0; } } } if (money < 0) { printf("bankrupt!!!"); printf("count : %d, continuous cnt : %d\n", cnt, cnt2 + 1); return 0; } printf("count : %d, continuous cnt : %d\n", cnt, cnt2 + 1); cnt2 = 0; } return 0; } | cs |
드디어 소스가 올라가네요 !! 짬짬히 만든코드라 조금 난잡합니다
| #include <stdio.h>#include<stdlib.h>#include<time.h>int running(int var1){ if (var1 == 0) //20%확률(이김) 일때 1리턴 return 1; else return 0; //80%확률(짐) 일때 0리턴}int win(int money, int var2){ if (var2 == 0) //1등 3배 return money * 3; else if (var2 == 1) //2등 2배 return money * 2;}int lose(int money){ return money;}int game(int var1, int var2, int* money, int betting){ int res; res = running(var1); if (res == 1) { if (var2 == 0) { *money = *money + win(betting, var2); printf("money : %10d \t betting: %10d Win*3\n", *money, betting); return 0; } if (var2 == 1) { *money = *money + win(betting, var2); printf("money : %10d \t betting: %10d Win*2\n", *money, betting); return 0; } //*money = *money + win(betting, var2); //printf("money : %10d \t betting: %10d Win\n", *money, betting); //return 0; } else if (res == 0) { *money = *money - lose(betting); printf("money : %10d \t betting: %10d Lose\n", *money, betting); return 1; } return money;}int main(void){ int i = 0, var1, var2, res, end; static int cnt = 0; static int cnt2 = 0; int money = 1000000000; int betting = 10000; var1 = rand() % 5; var2 = rand() % 2; srand(time(NULL)); ////for (i = 0; i < 20; i++) ////{ //// var1 = rand() % 5; //// var2 = rand() % 2; //// printf("%d %d\n", var1, var2); ////}rand값확인 유효값확인완료 // ////money=game(var1, var2, &money, betting); ////printf("money : %4d\n", money); //for (i = 0; i < 20; i++) //{ // var1 = rand() % 5; // var2 = rand() % 2; // game(var1, var2, &money, betting); // printf("money : %4d\n", money); //} ////1회게임완료 while (1) { var1 = rand() % 5; var2 = rand() % 2; betting = 10000; end = game(var1, var2, &money, betting); cnt++; if (end == 1) //패했을시 { while (1) //이길때까지 반복 { betting *= 2; var1 = rand() % 5; var2 = rand() % 2; end = game(var1, var2, &money, betting); cnt++; cnt2++; if (end == 0) break; if (money < 0) { printf("bankrupt!!!"); printf("count : %d, continuous cnt : %d\n", cnt, cnt2 + 1); return 0; } } } if (money < 0) { printf("bankrupt!!!"); printf("count : %d, continuous cnt : %d\n", cnt, cnt2 + 1); return 0; } printf("count : %d, continuous cnt : %d\n", cnt, cnt2 + 1); cnt2 = 0; } return 0;} |
#include <stdio.h>#include<stdlib.h>#include<time.h>int running(int var1){ if (var1 == 0) //20%확률(이김) 일때 1리턴 return 1; else return 0; //80%확률(짐) 일때 0리턴}int win(int money, int var2){ if (var2 == 0) //1등 3배 return money * 3; else if (var2 == 1) //2등 2배 return money * 2;}int lose(int money){ return money;}int game(int var1, int var2, int* money, int betting){ int res; res = running(var1); if (res == 1) { if (var2 == 0) { *money = *money + win(betting, var2); printf("money : %10d \t betting: %10d Win*3\n", *money, betting); return 0; } if (var2 == 1) { *money = *money + win(betting, var2); printf("money : %10d \t betting: %10d Win*2\n", *money, betting); return 0; } //*money = *money + win(betting, var2); //printf("money : %10d \t betting: %10d Win\n", *money, betting); //return 0; } else if (res == 0) { *money = *money - lose(betting); printf("money : %10d \t betting: %10d Lose\n", *money, betting); return 1; } return money;}int main(void){ int i = 0, var1, var2, res, end; static int cnt = 0; static int cnt2 = 0; int money = 1000000000; int betting = 10000; var1 = rand() % 5; var2 = rand() % 2; srand(time(NULL)); ////for (i = 0; i < 20; i++) ////{ //// var1 = rand() % 5; //// var2 = rand() % 2; //// printf("%d %d\n", var1, var2); ////}rand값확인 유효값확인완료 // ////money=game(var1, var2, &money, betting); ////printf("money : %4d\n", money); //for (i = 0; i < 20; i++) //{ // var1 = rand() % 5; // var2 = rand() % 2; // game(var1, var2, &money, betting); // printf("money : %4d\n", money); //} ////1회게임완료 while (1) { var1 = rand() % 5; var2 = rand() % 2; betting = 10000; end = game(var1, var2, &money, betting); cnt++; if (end == 1) //패했을시 { while (1) //이길때까지 반복 { betting *= 2; var1 = rand() % 5; var2 = rand() % 2; end = game(var1, var2, &money, betting); cnt++; cnt2++; if (end == 0) break; if (money < 0) { printf("bankrupt!!!"); printf("count : %d, continuous cnt : %d\n", cnt, cnt2 + 1); return 0; } } } if (money < 0) { printf("bankrupt!!!"); printf("count : %d, continuous cnt : %d\n", cnt, cnt2 + 1); return 0; } printf("count : %d, continuous cnt : %d\n", cnt, cnt2 + 1); cnt2 = 0; } return 0;}