fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. int main(void){
  6.  
  7. std::srand(std::time(NULL));
  8.  
  9. int wins_A = 0; int wins_B = 0;
  10. const int games = 10000;
  11.  
  12. for(int game=0; game<games; game++) {
  13. const int winning_door = rand()%3;
  14.  
  15. int choice_A = rand()%3; int choice_M = rand()%2;
  16. if (choice_M >= choice_A)
  17. choice_M ++;
  18.  
  19. if (choice_M == winning_door) {
  20. game --; continue;
  21. }
  22. else if (choice_A == winning_door)
  23. wins_A ++;
  24. else
  25. wins_B ++;
  26. }
  27.  
  28. std::cout << "A: " << 100.0*wins_A/games << "%, B: " << 100.0*wins_B/games << "%\n";
  29. }
  30.  
Success #stdin #stdout 0s 2728KB
stdin
Standard input is empty
stdout
A: 50.79%, B: 49.21%