Професионална програма
mincho.spasov91 avatar mincho.spasov91 9 Точки

PHP: Ex.5 - SoftUni Parking - Associative Arrays - 60/100

Моля за малко помощ. judge ми дава 60/100 и не мога да разбера къде ми е проблема. Това което виждам е че след като подаденото име което не фигурира в масива ми се оптечатва и не се премахва. Благодаря предварително


Задача -  05.SoftUni Parking

SoftUni just got a new parking lot. It's so fancy, it even has online parking validation. Except, the online service doesn't work. It can only receive users' data, but doesn't know what to do with it. Good thing you're on the dev team and know how to fix it, right?

Write a program, which validates parking for an online service. Users can register to park and unregister to leave.

The program receives 2 commands:

  • "register {username} {licensePlateNumber}":

    • The system only supports one car per user at the moment, so if a user tries to register another license plate, using the same username, the system should print:
      "ERROR: already registered with plate number {licensePlateNumber}"

    • If the aforementioned checks pass successfully, the plate can be registered, so the
      system should print:
      "{username} registered {licensePlateNumber} successfully"

  • "unregister {username}":

    • If the user is not present in the database, the system should print:
      "ERROR: user {username} not found"

    • If the aforementioned check passes successfully, the system should print:
      "{username} unregistered successfully"

After you execute all of the commands, print all the currently registered users and their license plates in the format:

  • "{username} => {licensePlateNumber}"


  • First line: n - number of commands - integer

  • Next n lines: commands in one of two possible formats:

    • Register: "register {username} {licensePlateNumber}"

    • Unregister: "unregister {username}"

The input will always be valid and you do not need to check it explicitly.





register John CS1234JS

register George JAVA123S

register Andy AB4142CD

register Jesica VR1223EE

unregister Andy

John registered CS1234JS successfully

George registered JAVA123S successfully

Andy registered AB4142CD successfully

Jesica registered VR1223EE successfully

Andy unregistered successfully

John => CS1234JS

George => JAVA123S

Jesica => VR1223EE




register Jony AA4132BB

register Jony AA4132BB

register Linda AA9999BB

unregister Jony

Jony registered AA4132BB successfully

ERROR: already registered with plate number AA4132BB

Linda registered AA9999BB successfully

Jony unregistered successfully

Linda => AA9999BB


register Jacob MM1111XX

register Anthony AB1111XX

unregister Jacob

register Joshua DD1111XX

unregister Lily

register Samantha AA9999BB



Jacob registered MM1111XX successfully

Anthony registered AB1111XX successfully

Jacob unregistered successfully

Joshua registered DD1111XX successfully

ERROR: user Lily not found

Samantha registered AA9999BB successfully

Anthony => AB1111XX

Joshua => DD1111XX

Samantha => AA9999BB





Judge - https://judge.softuni.bg/Contests/Practice/Index/1220#4

Моето решение - https://pastebin.com/VEQzD5mb




PHP Fundamentals 01/05/2020 17:43:55
dvdty avatar dvdty 484 Точки

Грешки които забелязвам:

  • unset($arr[$name]); имаш и 2та if-а на unregister 
  • няма нужда от continue и да добавяш в масив след if-овете
  • няма нужда да имаш вложени масиви, The system only supports one car per user at the moment ($arr[$name][] = $registrationNumber;)

Код след тези промени:


01/05/2020 18:11:59
mincho.spasov91 avatar mincho.spasov91 9 Точки

Благодари много ! :)