Advertisement
mastersan12

P05.SoftUni Parking

Mar 20th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P05.SoftUni_Parking
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int lines = int.Parse(Console.ReadLine());
  12.             var registered = new Dictionary<string, string>();
  13.            
  14.  
  15.             for (int currentLine = 1; currentLine <= lines; currentLine++)
  16.             {
  17.                 string[] command = Console.ReadLine().Split();
  18.                 string reg = command[0];
  19.                 string username = command[1];
  20.                
  21.  
  22.                 if (reg == "register")
  23.                 {
  24.                     string plate = command[2];
  25.                     if (!registered.ContainsKey(username))
  26.                     {
  27.                        
  28.                         registered.Add(username, plate);
  29.                         Console.WriteLine($"{username} registered {plate} successfully");
  30.                     }
  31.                     else
  32.                     {
  33.                         Console.WriteLine($"ERROR: already registered with plate number {plate}");
  34.                     }
  35.                 }
  36.                 else if (reg == "unregister")
  37.                 {
  38.                     if (!registered.ContainsKey(username))
  39.                     {
  40.                         Console.WriteLine($"ERROR: user {username} not found");
  41.                     }
  42.                     else
  43.                     {
  44.                         registered.Remove(username);
  45.                         Console.WriteLine($"{username} unregistered successfully");
  46.                     }
  47.                 }
  48.             }
  49.             foreach (var users in registered)
  50.             {
  51.                 Console.WriteLine($"{users.Key} => {users.Value}");
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement