Advertisement
ralitsa_d

Phonebook

Jun 14th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. namespace Dictionaries
  7. {
  8.     class Program
  9.     {
  10.         public static void Main(string[] args)
  11.         {
  12.             Dictionary<string, string> phoneDetails = new Dictionary<string, string>();
  13.  
  14.             List<string> commands = Console.ReadLine().Split(' ').ToList();
  15.             string token = commands[0];
  16.  
  17.             while (token != "END")
  18.             {
  19.                 switch (token)
  20.                 {
  21.                     case "A":
  22.                         string index = commands[1];
  23.                         string entry = commands[2];
  24.                         phoneDetails.Add(index, entry);
  25.                         break;
  26.                     case "S":
  27.                         string searched = commands[1];
  28.                         string result = null;
  29.                         if (phoneDetails.TryGetValue(searched, out result))
  30.                         {
  31.                             Console.WriteLine("{0} -> {1}", searched, result);
  32.                         }
  33.                         else
  34.                         {
  35.                             Console.WriteLine("Contact {0} does not exist.", searched);
  36.                         }
  37.                         break;
  38.                 }
  39.  
  40.                 commands = Console.ReadLine().Split(' ').ToList();
  41.                 token = commands[0];
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement