Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _05.ParkingValidation
- {
- class StartUp
- {
- static void Main()
- {
- int numberOfCommands = int.Parse(Console.ReadLine());
- Dictionary<string, string> parkingRegister = new Dictionary<string, string>();
- for (int i = 0; i < numberOfCommands; i++)
- {
- string[] args = Console.ReadLine().Split(' ');
- string command = args[0];
- string username = args[1];
- if (command == "register")
- {
- string licensePlate = args[2];
- string licensePlateNumbers = licensePlate.Substring(2, 4);
- string licensePlateLetters = licensePlate.Substring(0, 2) + licensePlate.Substring(6);
- bool isValid = false;
- if (licensePlate.Length == 8 && int.TryParse(licensePlateNumbers, out int ignor))
- {
- foreach (var letter in licensePlateLetters)
- {
- isValid = Char.IsLetter(letter) && Char.IsUpper(letter);
- if (!isValid)
- {
- break;
- }
- }
- }
- if (isValid == true)
- {
- if (!parkingRegister.ContainsKey(username))
- {
- if (!parkingRegister.ContainsValue(licensePlate))
- {
- parkingRegister.Add(username, licensePlate);
- Console.WriteLine($"{username} registered {licensePlate} successfully");
- }
- else
- {
- Console.WriteLine($"ERROR: license plate {licensePlate} is busy");
- }
- }
- else
- {
- Console.WriteLine($"ERROR: already registered with plate number {parkingRegister[username]}");
- }
- }
- else
- {
- Console.WriteLine($"ERROR: invalid license plate {licensePlate}");
- }
- }
- else if (command == "unregister")
- {
- if (parkingRegister.ContainsKey(username))
- {
- parkingRegister.Remove(username);
- Console.WriteLine($"user {username} unregistered successfully");
- }
- else
- {
- Console.WriteLine($"ERROR: user {username} not found");
- }
- }
- }
- if (parkingRegister.Count > 0)
- {
- Console.WriteLine(string.Join(Environment.NewLine, parkingRegister.Select(u => $"{u.Key} => {u.Value}")));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement