Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Feb26_2018
- {
- class MainClass
- {
- /* */
- public static void Main()
- {
- //int k = int.Parse(Console.ReadLine());
- //var input = Console.ReadLine()
- // .Split()
- // .Select(double.Parse)
- // .ToList();
- //var firstK = input.Take(k);
- //var asd = input.ToArray().Reverse();
- //Console.WriteLine(asd);
- char[] sep = {' '};
- string input;
- SortedDictionary<string, string> phoneBook = new SortedDictionary<string, string>();
- while((input = Console.ReadLine()) != "END")
- {
- string[] commands = input.Split(sep, StringSplitOptions.RemoveEmptyEntries);
- if(commands[0] == "A")
- {
- if(phoneBook.ContainsKey(commands[1]))
- {
- phoneBook[commands[1]] = commands[2];
- }
- else
- {
- phoneBook.Add(commands[1], commands[2]);
- }
- }
- else if(commands[0] == "S")
- {
- if(phoneBook.ContainsKey(commands[1]))
- {
- var name = commands[1];
- var number = phoneBook[commands[1]];
- Console.WriteLine("{0} -> {1}", name, number);
- }
- else
- {
- Console.WriteLine("Contact {0} does not exist.", commands[1]);
- }
- }
- else if(commands[0] == "ListAll")
- {
- foreach(var contact in phoneBook)
- {
- var name = contact.Key;
- var number = contact.Value;
- Console.WriteLine("{0} -> {1}", name, number);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement