Guest User

Untitled

a guest
Sep 30th, 2017
345
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class Tire
  4. {
  5. public $pressure;
  6. public $age;
  7.  
  8. public function __construct(float $pressure, int $age)
  9. {
  10. $this->pressure = $pressure;
  11. $this->age = $age;
  12. }
  13.  
  14. function isRightPressure()
  15. {
  16. return $this->pressure < 1;
  17. }
  18. }
  19.  
  20. class Cargo
  21. {
  22. public $weight;
  23. public $type;
  24.  
  25. public function __construct(int $weight, string $type)
  26. {
  27. $this->weight = $weight;
  28. $this->type = $type;
  29. }
  30. }
  31.  
  32. class Car
  33. {
  34. public $model;
  35. public $engine;
  36. public $cargo;
  37. public $tires;
  38.  
  39. function __construct(string $model, Engine $engine, Cargo $cargo, array $tires)
  40. {
  41. $this->model = $model;
  42. $this->engine = $engine;
  43. $this->cargo = $cargo;
  44. $this->tires = $tires;
  45. }
  46. }
  47.  
  48. class Engine
  49. {
  50. public $speed;
  51. public $power;
  52.  
  53. public function __construct(int $speed, int $power)
  54. {
  55. $this->speed = $speed;
  56. $this->power = $power;
  57. }
  58. }
  59.  
  60. $carCount = intval(rtrim(fgets(STDIN)));
  61.  
  62. $cars = [];
  63.  
  64. for ($i = 0; $i < $carCount; $i++) {
  65. $input = explode(' ', rtrim(fgets(STDIN)));
  66. list($model, $engineSpeed, $enginePower, $cargoWeight, $cargoType,
  67. $tire1Pressure, $tire1Age,
  68. $tire2Pressure, $tire2Age,
  69. $tire3Pressure, $tire3Age,
  70. $tire4Pressure, $tire4Age) = $input;
  71.  
  72. $engine = new Engine(intval($engineSpeed), intval($enginePower));
  73. $cargo = new Cargo(intval($cargoWeight), $cargoType);
  74. $tires = [new Tire(floatval($tire1Pressure), intval($tire1Age)), new Tire(floatval($tire2Pressure), intval($tire2Age)),
  75. new Tire(floatval($tire3Pressure), intval($tire3Age)), new Tire(floatval($tire4Pressure), intval($tire4Age))];
  76. $currentCar = new Car($model, $engine, $cargo, $tires);
  77.  
  78. $cars[] = $currentCar;
  79. }
  80.  
  81. $command = rtrim(fgets(STDIN));
  82.  
  83.  
  84. if ($command === 'fragile') {
  85. foreach ($cars as $car) {
  86. if ($car->cargo->type === 'fragile'){
  87. foreach ($car->tires as $tire) {
  88. if ($tire->isRightPressure()){
  89. echo $car->model . "\n";
  90. break;
  91. }
  92. }
  93. }
  94. }
  95. }
  96. else if ($command === 'flamable'){
  97. foreach ($cars as $car) {
  98. if ($car->cargo->type === 'flamable'){
  99. if ($car->engine->power > 250){
  100. echo $car->model . "\n";
  101. }
  102. }
  103. }
  104. }
RAW Paste Data