viraco4a

Untitled

Dec 29th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03._Phonebook
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string[] inputs = Console.ReadLine().Split(' ').ToArray();
  12. var phoneBook = new SortedDictionary<string, string>();
  13. var output = new List<string>();
  14. bool tmp = false;
  15.  
  16. while (inputs[0] != "END")
  17. {
  18. if (inputs[0] == "A")
  19. {
  20. if (phoneBook.ContainsKey(inputs[1]))
  21. {
  22. phoneBook[inputs[1]] = inputs[2];
  23. }
  24. else
  25. {
  26. phoneBook.Add(inputs[1], inputs[2]);
  27. }
  28. }
  29. else if (inputs[0] == "S")
  30.  
  31. if (phoneBook.ContainsKey(inputs[1]))
  32. {
  33. output.Add(inputs[1] + " -> " + phoneBook[inputs[1]]);
  34. //print right here when input[0] = S and the entry exists:
  35. Console.WriteLine($"{inputs[1]} -> {phoneBook[inputs[1]]}");
  36. }
  37. else
  38. {
  39. //output.Add("Contact " + inputs[1] + " does not exist.");
  40. //output.Remove(inputs[1]);
  41. //just print the statement here (if the input[0] doesn't exist:
  42. Console.WriteLine("Contact " + inputs[1] + " does not exist.");
  43. }
  44.  
  45.  
  46. else if (inputs[0] == "ListAll")
  47. {
  48. tmp = true;
  49. //bring the foreach printing inside this while loop:
  50. foreach (var item in phoneBook)
  51. {
  52. Console.WriteLine($"{item.Key} -> {item.Value}");
  53. }
  54. }
  55.  
  56. inputs = Console.ReadLine().Split(' ').ToArray();
  57. }
  58.  
  59. //Console.WriteLine(string.Join("\n", output));
  60. //if (tmp)
  61. //{
  62. //foreach (var item in phoneBook)
  63. //{
  64. // Console.WriteLine($"{item.Key} -> {item.Value}");
  65. //}
  66. //}
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment