Advertisement
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 _05.Parking_Validation
- {
- class Program
- {
- static void Main(string[] args)
- {
- var n = int.Parse(Console.ReadLine());
- var userLicense = new Dictionary<string, string>();
- for (int i = 0; i < n; i++)
- {
- var input = Console.ReadLine();
- var command = input
- .Split()
- .ToArray()[0];
- var username = input
- .Split()
- .ToArray()[1];
- switch (command)
- {
- case "register":
- var license = input
- .Split()
- .ToArray()[2];
- if (!IsValid(license))
- {
- Console.WriteLine($"ERROR: invalid license plate {license}");
- break;
- }
- if (userLicense.ContainsKey(username))
- {
- Console.WriteLine($"ERROR: already registered " +
- $"with plate number {userLicense[username]}");
- break;
- }
- if (userLicense.ContainsValue(license))
- {
- Console.WriteLine($"ERROR: license plate {license} is busy");
- break;
- }
- userLicense[username] = license;
- Console.WriteLine($"{username} registered {license} successfully");
- break;
- case "unregister":
- if (!userLicense.ContainsKey(username))
- {
- Console.WriteLine($"ERROR: user {username} not found");
- break;
- }
- userLicense.Remove(username);
- Console.WriteLine($"user {username} unregistered successfully");
- break;
- }
- }
- foreach (var pair in userLicense)
- {
- Console.WriteLine($"{pair.Key} => {pair.Value}");
- }
- }
- private static bool IsValid(string license)
- {
- string pattern = "([A-Z]{2})([0-9]{4})([A-Z]{2})";
- Regex regex = new Regex(pattern);
- Match match = regex.Match(license);
- return match.Success;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement