Advertisement
ShadowEmbrace

SoftUni Parking

Nov 12th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2.  
  3. $n = intval(readline());
  4.  
  5. $parking = [];
  6.  
  7. for ($i = 0; $i < $n; $i++) {
  8.     $parkingLot = explode(' ', readline());
  9.     $username = $parkingLot[1];
  10.  
  11.     if ($parkingLot[0] === 'register') {
  12.         $carNumber = $parkingLot[2];
  13.         if (key_exists($username, $parking)) {
  14.             echo "ERROR: already registered with plate number " . implode('', $parking[$username]) . PHP_EOL;
  15.         } else {
  16.             $parking[$username][] = $carNumber;
  17.             echo "$username registered $carNumber successfully" . PHP_EOL;
  18.         }
  19.     } elseif ($parkingLot[0] === 'unregister') {
  20.         if (!key_exists($username, $parking)) {
  21.             echo "ERROR: user $username not found" . PHP_EOL;
  22.         } else {
  23.             echo "$username unregistered successfully" . PHP_EOL;
  24.             unset($parking[$username]);
  25.         }
  26.     }
  27. }
  28.  
  29. foreach ($parking as $user => $carRegistration) {
  30.     echo "$user => " . implode('', $carRegistration) . PHP_EOL;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement