fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. int main ()
  6. {
  7. int nTrys=100000,nSer=50,nMon=10,stavka=1;
  8. int i,j,l, sCount=0,rNum;
  9. srand(time(NULL));
  10.  
  11. for (i=0;i<nTrys;i++){
  12. l = nMon;j = 0;
  13. while (j<nSer && l>0){
  14. rNum = rand()%37;
  15. if (rNum == 0) l-=stavka;
  16. else if (rNum <= 18) l+=stavka;
  17. else l-=stavka;
  18. j++;
  19. }
  20. if (l == 0) sCount++;
  21. }
  22. cout << "Разорился " << sCount << " из " << nTrys;
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0.16s 2680KB
stdin
Standard input is empty
stdout
Разорился 21098 из 100000