kvadrat4o

PhoneBookUpgrade

Jun 14th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. /*
  2.  * Created by SharpDevelop.
  3.  * User: DVasilev
  4.  * Date: 2017/06/14
  5.  * Time: 8:25 PM
  6.  *
  7.  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8.  */
  9. using System;
  10. using System.Linq;
  11. using System.Collections.Generic;
  12.  
  13.  
  14. namespace PhonebookUpgraded
  15. {
  16.     class Program
  17.     {
  18.         public static void Main(string[] args)
  19.         {
  20.             //Console.WriteLine("Hello World!");
  21.             SortedDictionary<string, string> phoneDetails = new SortedDictionary<string, string>();
  22.  
  23.             List<string> commands = Console.ReadLine().Split(' ').ToList();
  24.             string token = commands[0];
  25.  
  26.             while (token != "END")
  27.             {
  28.                 switch (token)
  29.                 {
  30.                     case "A":
  31.                         string index = commands[1];
  32.                         string entry = commands[2];
  33.                         phoneDetails.Add(index, entry);
  34.                         break;
  35.                     case "S":
  36.                         string searched = commands[1];
  37.                         string result = null;
  38.                         if (phoneDetails.TryGetValue(searched, out result))
  39.                         {
  40.                             Console.WriteLine("{0} -> {1}", searched, result);
  41.                         }
  42.                         else
  43.                         {
  44.                             Console.WriteLine("Contact {0} does not exist.", searched);
  45.                         }
  46.                         break;
  47.                     case "ListAll":
  48.                         foreach (var phone in phoneDetails)
  49.                         {
  50.                            Console.WriteLine("{0} -> {1}", phone.Key, phone.Value);
  51.                         }
  52.  
  53.                         break;
  54.                 }
  55.  
  56.                 commands = Console.ReadLine().Split(' ').ToList();
  57.                 token = commands[0];
  58.             }
  59.             Console.Write("Press any key to continue . . . ");
  60.             Console.ReadKey(true);
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment