Teo_Yanchev

Dictionaries - 05. SoftUniParking - C# Fundamentals

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