Advertisement
radidim

P05.SoftUni Parking (C# Shell App Paste)

Jul 27th, 2020
1,616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6.  
  7. namespace CSharp_Shell
  8. {
  9.  
  10.     public static class Program
  11.     {
  12.         public static void Main()
  13.         {
  14.            var parking = new Dictionary<string, string>();
  15.            var n = int.Parse(Console.ReadLine());
  16.            for(int i=0;i<n;i++)
  17.            {
  18.             var input = Console.ReadLine().Split();
  19.             var command = input[0];
  20.            
  21.             if(command == "register")
  22.             {
  23.             var username = input[1];
  24.             var licensePlateNumber= input[2];
  25.            
  26.            
  27.             if(!parking.ContainsKey(username))
  28.             {
  29.                 parking[username] = string.Empty;
  30.             }
  31.             if(parking[username] == string.Empty)
  32.                 {
  33.                     parking[username] = licensePlateNumber;
  34.                     Console.WriteLine($"{username} registered {licensePlateNumber} successfully");
  35.                    
  36.                 }  
  37.                 else
  38.                 {
  39.                     Console.WriteLine($"ERROR: already registered with plate number {licensePlateNumber}");
  40.                 }
  41.                
  42.             }
  43.            
  44.             else if(command=="unregister")
  45.             {
  46.            
  47.             var username = input[1];
  48.             if(!parking.ContainsKey(username))
  49.             {
  50.                 Console.WriteLine($"ERROR: user {username} not found");
  51.  
  52.             }
  53.             else
  54.             {
  55.                
  56.                 Console.WriteLine($"{username} unregistered successfully");
  57.                 parking.Remove(username);
  58.             }
  59.  
  60.            
  61.             }
  62.            
  63.            }
  64.            
  65.            foreach(var kvp in parking)
  66.            {
  67.             Console.WriteLine($"{kvp.Key} => {kvp.Value}");
  68.            }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement