Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _13.PhonebookUpdate
- {
- class PhonebookUpdate
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- SortedDictionary<string, string> phonebook = new SortedDictionary<string, string>();
- List<string> result = new List<string>();
- bool listed = false;
- while (input.ToUpper() != "END")
- {
- if (input == "ListAll")
- {
- listed = true;
- input = Console.ReadLine();
- continue;
- }
- string[] text = input.Split(' ');
- string action = text[0];
- string name = text[1];
- if (action == "A")
- {
- string number = text[2];
- if (phonebook.ContainsKey(name))
- phonebook[name] = number;
- else
- phonebook.Add(name, number);
- }
- else if (action == "S")
- {
- string answer = "";
- if (phonebook.ContainsKey(name))
- answer = string.Format("{0} -> {1}", name, phonebook[name]);
- else
- answer = string.Format("Contact {0} does not exist.", name);
- result.Add(answer);
- }
- input = Console.ReadLine();
- }
- if (listed)
- {
- foreach (var contact in phonebook)
- {
- Console.WriteLine("{0} -> {1}", contact.Key, contact.Value);
- }
- }
- else
- {
- Console.WriteLine(string.Join("\n", result));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment