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;
- namespace ConsoleApp8
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberOfCommands = int.Parse(Console.ReadLine());
- Dictionary<string, string> usernamePlate = new Dictionary<string, string>();
- for (int i = 0; i < numberOfCommands; i++)
- {
- string inputLine = Console.ReadLine();
- var elements = inputLine.Split(' ').ToArray();
- string command = elements[0];
- string username = elements[1];
- if (command == "register")
- {
- string licensePlate = elements[2];
- //АА1234BB is Valid Plate
- bool isValidPlate = licensePlate.Length == 8
- && char.IsUpper(licensePlate[0])
- && char.IsUpper(licensePlate[1])
- && char.IsUpper(licensePlate[7])
- && char.IsUpper(licensePlate[6])
- && char.IsDigit(licensePlate[2])
- && char.IsDigit(licensePlate[3])
- && char.IsDigit(licensePlate[4])
- && char.IsDigit(licensePlate[5]);
- if (isValidPlate)
- {
- if (!usernamePlate.ContainsKey(username))
- {
- if (!usernamePlate.ContainsValue(licensePlate))
- {
- usernamePlate.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 {usernamePlate[username]}");
- }
- }
- else
- {
- Console.WriteLine($"ERROR: invalid license plate {licensePlate}");
- }
- }
- else
- {
- if (!usernamePlate.ContainsKey(username))
- {
- Console.WriteLine($"ERROR: user {username} not found");
- }
- else
- {
- Console.WriteLine($"user {username} unregistered successfully");
- usernamePlate.Remove(username);
- }
- }
- }
- foreach (var item in usernamePlate)
- {
- Console.WriteLine($"{item.Key} => {item.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement