Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace _22_05_ParkingValidation
- {
- class ParkingValidation
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- var database = new Dictionary<string, string>();
- for (int i = 0; i < n; i++)
- {
- var input = Console.ReadLine();
- var inputArray = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(s => s.Trim())
- .ToArray();
- var command = inputArray[0].ToLower();
- var userName = inputArray[1];
- var plate = inputArray[2];
- var paternPlate = new Regex(@"^[A - Z]{ 2}\d{ 4}[A-Z]{2}$");
- if (command == "register")
- {
- var match = paternPlate.Match(plate);
- if (!match.Success)
- {
- Console.WriteLine($"ERROR: invalid license plate {plate}");
- continue;
- }
- else if (!database.ContainsKey(userName))
- {
- database.Add(userName, plate);
- Console.WriteLine($"{userName} registered {plate} successfully");
- }
- else if (database.ContainsKey(userName) && database.ContainsValue(plate))
- {
- Console.WriteLine($"ERROR: already registered with plate number {database[userName]}");
- }
- else if (database.ContainsValue(plate))
- {
- Console.WriteLine($"ERROR: license plate {plate} is busy");
- }
- }
- else if (command == "unregister")
- {
- if (!database.ContainsKey(userName))
- {
- Console.WriteLine($"ERROR: user {userName} not found");
- }
- else
- {
- database.Remove(database[userName]);
- Console.WriteLine($"user {userName} unregistered successfully");
- }
- }
- }
- foreach (var pair in database)
- {
- Console.WriteLine($"{pair.Key} => {pair.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment