Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. string input = "";
  2. string[] commands;
  3. var phonebook = new SortedDictionary<string, string>();
  4. while (input != "END")
  5. {
  6. input = Console.ReadLine();
  7. commands = input.Split();
  8. if (commands[0] == "A")
  9. {
  10. if (phonebook.ContainsKey(commands[1]))
  11. {
  12. phonebook[commands[1]] = commands[2];
  13. }
  14. else
  15. {
  16. phonebook.Add(commands[1], commands[2]);
  17. }
  18. }
  19. else if (commands[0] == "S")
  20. {
  21. if (phonebook.ContainsKey(commands[1]))
  22. {
  23. Console.WriteLine(commands[1] + " -> " + phonebook[commands[1]]);
  24. }
  25. else
  26. {
  27. Console.WriteLine("Contact {0} does not exist.", commands[1]);
  28. }
  29. }
  30. else if (commands[0] == "ListAll") {
  31. foreach (var item in phonebook)
  32. {
  33. Console.WriteLine(item.Key + " -> " + item.Value);
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement