Advertisement
Guest User

Untitled

a guest
May 9th, 2018
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _01.Phonebook
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string[] numbers = Console.ReadLine()
  14. .Split(' ')
  15. .ToArray();
  16.  
  17. Dictionary<string, string> phoneBook = new Dictionary<string, string>();
  18.  
  19. string command = numbers[0];
  20. while (command != "END")
  21. {
  22. if (command == "A")
  23. {
  24. if (!phoneBook.ContainsKey(numbers[1]))
  25. {
  26. phoneBook.Add(numbers[1], numbers[2]);
  27. }
  28.  
  29. phoneBook[numbers[1]] = numbers[2];
  30.  
  31. }
  32. else if (command == "S")
  33. {
  34. if (phoneBook.ContainsKey(numbers[1]))
  35. {
  36. foreach (KeyValuePair<string, string> contact in phoneBook)
  37. {
  38. if (contact.Key == numbers[1])
  39. {
  40. Console.WriteLine($"{contact.Key} -> {contact.Value}");
  41. }
  42. }
  43. }
  44. else
  45. {
  46. Console.WriteLine($"Contact {numbers[1]} does not exist.");
  47. }
  48. }
  49. numbers = Console.ReadLine()
  50. .Split(' ')
  51. .ToArray();
  52. command = numbers[0];
  53. }
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement