Advertisement
Guest User

Untitled

a guest
Mar 11th, 2017
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class Person
  5. {
  6. private $name;
  7. private $age;
  8. public function __construct(string $name, int $age) {
  9. $this->name = $name;
  10. $this->age = $age;
  11. }
  12.  
  13. public function setName(string $name)
  14. {
  15. $this->name = $name;
  16. }
  17. public function getName(): string
  18. {
  19. return $this->name;
  20. }
  21. public function setAge(int $age)
  22. {
  23. $this->age = $age;
  24. }
  25. public function getAge(): int
  26. {
  27. return $this->age;
  28. }
  29.  
  30. public function __toString()
  31. {
  32. return $this->name . " " . $this->age;
  33. }
  34.  
  35. }
  36.  
  37. $numberOfInputs = trim(fgets(STDIN));
  38.  
  39.  
  40. $outt = [];
  41. while ($numberOfInputs > 0){
  42. $input = trim(fgets(STDIN));
  43. $input = explode(' ', $input);
  44.  
  45. $name = $input[0];
  46. $age = intval($input[1]);
  47. $check = checkAge($age);
  48.  
  49.  
  50. if ($check) {
  51. $person = new Person($name, $age);
  52. $outt[$name] = $age;
  53. }
  54.  
  55.  
  56. $numberOfInputs--;
  57. }
  58.  
  59. function checkAge ($age){
  60. return $age > 30;
  61. }
  62.  
  63. function sortt($a, $b){
  64. return strcmp($a->getName(), $b->getName());
  65. }
  66.  
  67. ksort($outt);
  68.  
  69. foreach ($outt as $key => $value){
  70. echo $key . " - " .$value . "\n";
  71. }
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement