Advertisement
Guest User

05. Parking Validation

a guest
Jun 25th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace ConsoleApp8
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int numberOfCommands = int.Parse(Console.ReadLine());
  14.             Dictionary<string, string> usernamePlate = new Dictionary<string, string>();
  15.             for (int i = 0; i < numberOfCommands; i++)
  16.             {
  17.                 string inputLine = Console.ReadLine();
  18.                 var elements = inputLine.Split(' ').ToArray();
  19.                 string command = elements[0];
  20.                 string username = elements[1];
  21.                 if (command == "register")
  22.                 {
  23.                     string licensePlate = elements[2];
  24.                     //АА1234BB is Valid Plate
  25.                     bool isValidPlate = licensePlate.Length == 8
  26.                         && char.IsUpper(licensePlate[0])
  27.                         && char.IsUpper(licensePlate[1])
  28.                         && char.IsUpper(licensePlate[7])
  29.                         && char.IsUpper(licensePlate[6])
  30.                         && char.IsDigit(licensePlate[2])
  31.                         && char.IsDigit(licensePlate[3])
  32.                         && char.IsDigit(licensePlate[4])
  33.                         && char.IsDigit(licensePlate[5]);
  34.                     if (isValidPlate)
  35.                     {
  36.                         if (!usernamePlate.ContainsKey(username))
  37.                         {
  38.                             if (!usernamePlate.ContainsValue(licensePlate))
  39.                             {
  40.                                 usernamePlate.Add(username, licensePlate);
  41.                                 Console.WriteLine($"{username} registered {licensePlate} successfully");
  42.                             }
  43.                             else
  44.                             {
  45.                                 Console.WriteLine($"ERROR: license plate {licensePlate} is busy");
  46.                             }
  47.                         }
  48.                         else
  49.                         {
  50.                             Console.WriteLine($"ERROR: already registered with plate number {usernamePlate[username]}");
  51.                         }
  52.                     }
  53.                     else
  54.                     {
  55.                         Console.WriteLine($"ERROR: invalid license plate {licensePlate}");
  56.                     }
  57.                 }
  58.                 else
  59.                 {
  60.                     if (!usernamePlate.ContainsKey(username))
  61.                     {
  62.                         Console.WriteLine($"ERROR: user {username} not found");
  63.                     }
  64.                     else
  65.                     {
  66.                         Console.WriteLine($"user {username} unregistered successfully");
  67.                         usernamePlate.Remove(username);
  68.                     }
  69.                 }
  70.             }
  71.             foreach (var item in usernamePlate)
  72.             {
  73.                 Console.WriteLine($"{item.Key} => {item.Value}");
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement