Advertisement
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]]);
- }
- else
- {
- output.Add("Contact " + inputs[1] + " does not exist.");
- output.Remove(inputs[1]);
- }
- else if (inputs[0] == "ListAll")
- {
- tmp = true;
- }
- 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
Advertisement