Advertisement
svetlyoek

Untitled

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