Advertisement
KKK99

05_SoftuniParking

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