Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $n = intval(readline());
- $parking = [];
- for ($i = 0; $i < $n; $i++) {
- $parkingLot = explode(' ', readline());
- $username = $parkingLot[1];
- if ($parkingLot[0] === 'register') {
- $carNumber = $parkingLot[2];
- if (key_exists($username, $parking)) {
- echo "ERROR: already registered with plate number " . implode('', $parking[$username]) . PHP_EOL;
- } else {
- $parking[$username][] = $carNumber;
- echo "$username registered $carNumber successfully" . PHP_EOL;
- }
- } elseif ($parkingLot[0] === 'unregister') {
- if (!key_exists($username, $parking)) {
- echo "ERROR: user $username not found" . PHP_EOL;
- } else {
- echo "$username unregistered successfully" . PHP_EOL;
- unset($parking[$username]);
- }
- }
- }
- foreach ($parking as $user => $carRegistration) {
- echo "$user => " . implode('', $carRegistration) . PHP_EOL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement