#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 = 100000000; int betting = 10000;
////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)
{
betting = 10000;
end = game(var1, var2, &money, betting); cnt++;
if (end == 1) //패했을시
{
while (1) //이길때까지 반복
{
betting *= 2;
end = game(var1, var2, &money, betting); cnt++; cnt2++;
if (end == 0)
break;
if (money < 0)
{
printf("count : %d, continuous cnt : %d\n", cnt
, cnt2
+ 1); return 0;
}
}
}
if (money < 0)
{
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;
}
I2luY2x1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oIm1vbmV5IDogJTRkXG4iLCBtb25leSk7CgkvL30JCgkvLy8vMe2ajOqyjOyehOyZhOujjAoKCgl3aGlsZSAoMSkKCXsKCQl2YXIxID0gcmFuZCgpICUgNTsKCQl2YXIyID0gcmFuZCgpICUgMjsKCQliZXR0aW5nID0gMTAwMDA7CgkJZW5kID0gZ2FtZSh2YXIxLCB2YXIyLCAmbW9uZXksIGJldHRpbmcpOyBjbnQrKzsKCgkJaWYgKGVuZCA9PSAxKQkvL+2MqO2WiOydhOyLnAoJCXsKCgkJCXdoaWxlICgxKQkvL+ydtOq4uOuVjOq5jOyngCDrsJjrs7UKCQkJewoJCQkJYmV0dGluZyAqPSAyOwoJCQkJdmFyMSA9IHJhbmQoKSAlIDU7CgkJCQl2YXIyID0gcmFuZCgpICUgMjsKCQkJCWVuZCA9IGdhbWUodmFyMSwgdmFyMiwgJm1vbmV5LCBiZXR0aW5nKTsgY250Kys7IGNudDIrKzsKCgkJCQlpZiAoZW5kID09IDApCgkJCQkJYnJlYWs7CgoJCQkJaWYgKG1vbmV5IDwgMCkKCQkJCXsKCQkJCQlwcmludGYoImJhbmtydXB0ISEhIik7CgkJCQkJcHJpbnRmKCJjb3VudCA6ICVkLCBjb250aW51b3VzIGNudCA6ICVkXG4iLCBjbnQsIGNudDIgKyAxKTsKCQkJCQlyZXR1cm4gMDsKCQkJCX0KCQkJfQoJCX0KCgkJaWYgKG1vbmV5IDwgMCkKCQl7CgkJCXByaW50ZigiYmFua3J1cHQhISEiKTsKCQkJcHJpbnRmKCJjb3VudCA6ICVkLCBjb250aW51b3VzIGNudCA6ICVkXG4iLCBjbnQsIGNudDIgKyAxKTsKCQkJcmV0dXJuIDA7CgkJfQoJCXByaW50ZigiY291bnQgOiAlZCwgY29udGludW91cyBjbnQgOiAlZFxuIiwgY250LCBjbnQyICsgMSk7CgkJY250MiA9IDA7Cgl9CglyZXR1cm4gMDsKfQ==
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