fork download
  1. #include <iostream>
  2. #include <random>
  3.  
  4. int main()
  5. {
  6. std::random_device rd;
  7. std::mt19937 gen(rd());
  8. std::uniform_int_distribution<> dis(0, 1);
  9.  
  10. unsigned const trials = 100000;
  11. unsigned survive = 0;
  12. unsigned trials_that_happened = 0;
  13. for(unsigned i = 0; i < trials; ++i)
  14. {
  15. int clear1 = dis(gen);
  16. int clear2 = dis(gen);
  17. if (clear1 )
  18. if(clear1 && clear2) //both female, one didn't croak
  19. {
  20. continue;
  21. }
  22. if(clear1 || clear2) //at least one was female
  23. {
  24. ++survive;
  25. }
  26. ++trials_that_happened;
  27. }
  28. std::cout << survive << std::endl;
  29. std::cout << (survive/1.0/trials_that_happened)*100.0 << "%" << std::endl;
  30. }
Success #stdin #stdout 0.01s 3416KB
stdin
Standard input is empty
stdout
50150
66.7563%