fork(1) download
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. int rang, stars, v, wins;
  8. rang = 10;
  9. stars = 1;
  10. wins = 0;
  11. for (int i=0;i<1050;i++) //N_games
  12. {
  13. v = rand() % 2;//=0-lose =1-win
  14. wins = wins + v;
  15. if ((stars>0)&&(stars<5)) //1-4stars
  16. {
  17. stars=stars+2*v-1;
  18. }
  19. else // 0,5 stars
  20. {
  21. if (v==0) // LOSE
  22. {
  23. if(stars==0)
  24. {
  25. if (rang!=10)
  26. {
  27. stars = 5;
  28. rang++;
  29. }
  30. }
  31. else
  32. stars--;
  33. }
  34. else // v=1 WIN
  35. {
  36. if(stars==5)
  37. {
  38. rang--;
  39. stars = 0;
  40. }
  41. else
  42. stars++;
  43. }
  44. }
  45. }
  46. std::cout << "rang=" << rang << " stars=" << stars << " wins="<< wins;
  47. return 0;
  48. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
rang=5 stars=0 wins=521