Advertisement
MeliDragon

Untitled

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