Advertisement
Spocoman

04. SoftUni Parking

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