Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _03._Phonebook
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] inputs = Console.ReadLine().Split(' ').ToArray();
- var phoneBook = new SortedDictionary<string, string>();
- var output = new List<string>();
- bool tmp = false;
- while (inputs[0] != "END")
- {
- if (inputs[0] == "A")
- {
- if (phoneBook.ContainsKey(inputs[1]))
- {
- phoneBook[inputs[1]] = inputs[2];
- }
- else
- {
- phoneBook.Add(inputs[1], inputs[2]);
- }
- }
- else if (inputs[0] == "S")
- if (phoneBook.ContainsKey(inputs[1]))
- {
- output.Add(inputs[1] + " -> " + phoneBook[inputs[1]]);
- //print right here when input[0] = S and the entry exists:
- Console.WriteLine($"{inputs[1]} -> {phoneBook[inputs[1]]}");
- }
- else
- {
- //output.Add("Contact " + inputs[1] + " does not exist.");
- //output.Remove(inputs[1]);
- //just print the statement here (if the input[0] doesn't exist:
- Console.WriteLine("Contact " + inputs[1] + " does not exist.");
- }
- else if (inputs[0] == "ListAll")
- {
- tmp = true;
- //bring the foreach printing inside this while loop:
- foreach (var item in phoneBook)
- {
- Console.WriteLine($"{item.Key} -> {item.Value}");
- }
- }
- inputs = Console.ReadLine().Split(' ').ToArray();
- }
- //Console.WriteLine(string.Join("\n", output));
- //if (tmp)
- //{
- //foreach (var item in phoneBook)
- //{
- // Console.WriteLine($"{item.Key} -> {item.Value}");
- //}
- //}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment