Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 10.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 it 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 a parking place for an online service. Users can register to park and unregister to leave.
- The program receives 2 commands:
- • "register {username} {licensePlateNumber}":
- o 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}"
- o If the aforementioned checks passes successfully, the plate can be registered, so the system should print:
- "{username} registered {licensePlateNumber} successfully"
- • "unregister {username}":
- o If the user is not present in the database, the system should print:
- "ERROR: user {username} not found"
- o 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}"
- Input
- • First line: n – number of commands – integer
- • Next n lines: commands in one of the two possible formats:
- o Register: "register {username} {licensePlateNumber}"
- o Unregister: "unregister {username}"
- The input will always be valid and you do not need to check it explicitly.
- Examples
- Input Output
- 5
- register John CS1234JS John registered CS1234JS successfully
- register George JAVA123S George registered JAVA123S successfully
- register Andy AB4142CD Andy registered AB4142CD successfully
- register Jesica VR1223EE Jesica registered VR1223EE successfully
- unregister Andy Andy unregistered successfully
- John => CS1234JS
- George => JAVA123S
- Jesica => VR1223EE
- 4
- register Jony AA4132BB Jony registered AA4132BB successfully
- register Jony AA4132BB ERROR: already registered with plate number AA4132BB
- register Linda AA9999BB Linda registered AA9999BB successfully
- unregister Jony Jony unregistered successfully
- Linda => AA9999BB
- 6
- register Jacob MM1111XX Jacob registered MM1111XX successfully
- register Anthony AB1111XX Anthony registered AB1111XX successfully
- unregister Jacob Jacob unregistered successfully
- register Joshua DD1111XX Joshua registered DD1111XX successfully
- unregister Lily ERROR: user Lily not found
- register Samantha AA9999BB Samantha registered AA9999BB successfully
- Joshua => DD1111XX
- Anthony => AB1111XX
- Samantha => AA9999BB
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _04Orders
- {
- class Program
- {
- static void Main(string[] args)
- {
- var numberCommands = int.Parse(Console.ReadLine());
- var username = new Dictionary<string, string>();
- for (int i = 1; i <= numberCommands; i++)
- {
- var command = Console.ReadLine().Split();
- if (command[0] == "register")
- {
- if (username.ContainsKey(command[1]) == false)
- {
- username.Add(command[1], command[2]);
- Console.WriteLine($"{command[1]} registered {username[command[1]]} successfully");
- } //Или command[2]
- else
- {
- Console.WriteLine($"ERROR: already registered with plate number {command[2]}");
- } //Или username[command[1]]
- }
- else
- {
- if (username.ContainsKey(command[1]) == false)
- {
- Console.WriteLine($"ERROR: user {command[1]} not found");
- }
- else
- {
- username.Remove(command[1]);
- Console.WriteLine($"{command[1]} unregistered successfully");
- }
- }
- }
- foreach (var item in username)
- {
- Console.WriteLine($"{item.Key} => {item.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment