Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Privates
- {
- private $id;
- private $firstName;
- private $secoundName;
- private $salary;
- public function __construct($id, string $firstName, string $secoundName, float $salary)
- {
- $this->id = $id;
- $this->firstName = $firstName;
- $this->secoundName = $secoundName;
- $this->salary = $salary;
- }
- public function __toString()
- {
- $printSalary = number_format($this->salary, 2, '.', '');
- return " Name: {$this->firstName} {$this->secoundName} Id: {$this->id} Salary: {$printSalary}";
- }
- }
- $privates = [];
- while (true) {
- $input = trim(fgets(STDIN));
- if ($input == "End") {
- break;
- }
- $input = explode(" ", $input);
- if (count($input) == 5 && trim($input[0]) == "Private") {
- $id = trim($input[1]);
- $firstName = trim($input[2]);
- $secoundName = trim($input[3]);
- $salary = number_format(floatval($input[4]), 2, '.', '');
- $newPrivate = new Privates($id, $firstName, $secoundName, $salary);
- echo "Name: {$firstName} {$secoundName} Id: {$id} Salary: {$salary}" . PHP_EOL;
- array_push($privates, $newPrivate);
- }
- if (count($input) == 6 && trim($input[0]) == "Commando") {
- $id = trim($input[1]);
- $firstName = trim($input[2]);
- $secoundName = trim($input[3]);
- $salary = number_format(floatval($input[4]), 2, '.', '');
- $corps = trim($input[5]);
- echo "Name: {$firstName} {$secoundName} Id: {$id} Salary: {$salary}" . PHP_EOL;
- echo "Corps: {$corps}" . PHP_EOL;
- echo "Missions:" . PHP_EOL;
- }
- if (count($input) == 7 && trim($input[0]) == "LeutenantGeneral") {
- $id = trim($input[1]);
- $firstName = trim($input[2]);
- $secoundName = trim($input[3]);
- $salary = number_format(floatval($input[4]), 2, '.', '');
- $privateID1 = trim($input[5]);
- $privateID2 = trim($input[6]);
- echo "Name: {$firstName} {$secoundName} Id: {$id} Salary: {$salary}" . PHP_EOL;
- }
- }
- if(count($privates)!=0){
- echo "Privates:" . PHP_EOL;
- foreach ($privates as $privatePerson) {
- echo $privatePerson . PHP_EOL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement