Advertisement
natalyayemelyanova

Олег Тереза 4

Apr 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. <?php
  2. $people=[
  3. ['b'=>1930, 'd'=>1934],
  4. ['b'=>1965, 'd'=>1995],
  5. ['b'=>1956, 'd'=>1966],
  6. ['b'=>1856, 'd'=>1915],
  7. ['b'=>1760, 'd'=>1826],
  8. ['b'=>1, 'd'=>1909],
  9. ['b'=>2000, 'd'=>2007],
  10. ['b'=>1450, 'd'=>1687]
  11. ];
  12.  
  13. echo getYearWithMaxNumberHumanAlive($people);
  14.  
  15.  
  16. function getYearWithMaxNumberHumanAlive(array $people)
  17. {
  18. $yearWithMaxLiveHuman = 0;
  19. $maxCount = 0;
  20. for($year=1900; $year<2000; $year++) {
  21. $count = 0;
  22. foreach($people as $human) {
  23. if($human['b'] < $year && $human['d'] >= $year) {
  24. $count++;
  25. }
  26. }
  27. if($maxCount < $count) {
  28. $yearWithMaxLiveHuman = $year;
  29. $maxCount = $count;
  30. }
  31. }
  32. return $yearWithMaxLiveHuman;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement