Advertisement
petyaminkova91

Untitled

Nov 12th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _05_SoftUniParking
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int commandCount = int.Parse(Console.ReadLine());
  12. Dictionary<string, string> dataBase = new Dictionary<string, string>();
  13.  
  14. for (int i = 0; i < commandCount; i++)
  15. {
  16. string[] commands = Console.ReadLine().Split();
  17.  
  18. string command = commands[0];
  19. string userName = commands[1];
  20.  
  21. switch (command)
  22. {
  23. case "register":
  24. string licensePlateNumber = commands[2];
  25. Register(userName, licensePlateNumber, dataBase);
  26. break;
  27. case "unregister":
  28. Unregister(userName, dataBase);
  29. break;
  30. }
  31. }
  32.  
  33. foreach (var user in dataBase)
  34. {
  35. Console.WriteLine($"{user.Key} => {user.Value}");
  36. }
  37. }
  38.  
  39. static void Register(string userName, string licensePlateNumber, Dictionary<string, string> dataBase)
  40. {
  41. bool isRegistered = CheckIfTheUserIsRegistered(userName, dataBase);
  42.  
  43. if (isRegistered)
  44. {
  45. Console.WriteLine($"ERROR: already registered with plate number {licensePlateNumber}");
  46. }
  47. else
  48. {
  49. dataBase.Add(userName, licensePlateNumber);
  50. Console.WriteLine($"{userName} registered {licensePlateNumber} successfully");
  51. }
  52. }
  53.  
  54. static void Unregister(string userName, Dictionary<string, string> database)
  55. {
  56. bool isRegistered = CheckIfTheUserIsRegistered(userName, database);
  57.  
  58. if (isRegistered)
  59. {
  60. database.Remove(userName);
  61. Console.WriteLine($"{userName} unregistered successfully");
  62. }
  63. else
  64. {
  65. Console.WriteLine($"ERROR: user {userName} not found");
  66. }
  67. }
  68.  
  69. static bool CheckIfTheUserIsRegistered(string userName, Dictionary<string, string> register)
  70. {
  71. if (register.ContainsKey(userName))
  72. {
  73. return true;
  74. }
  75. else
  76. {
  77. return false;
  78. }
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement