Advertisement
Guest User

Untitled

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