Advertisement
martinvalchev

Phonebook_Upgrade

Feb 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Phonebook_Upgrade
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             Dictionary<string, string> phonebook = new Dictionary<string, string>();
  15.             string[] funcion = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  16.  
  17.             while (funcion[0] != "END")
  18.             {
  19.                 DifrenFuncion(phonebook, funcion);
  20.                 funcion = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  21.             }
  22.  
  23.         }
  24.  
  25.         private static void DifrenFuncion(Dictionary<string, string> phonebook, string[] funcion)
  26.         {
  27.             switch (funcion[0])
  28.             {
  29.                 case "A":
  30.                     phonebook[funcion[1]] = funcion[2];
  31.                     break;
  32.                 case "S":
  33.                     if (phonebook.ContainsKey(funcion[1]))
  34.                     {
  35.                         Console.WriteLine($"{funcion[1]} -> {phonebook[funcion[1]]}");
  36.                         break;
  37.                     }
  38.                     Console.WriteLine($"Contact {funcion[1]} does not exist.");
  39.                     break;
  40.                 case "ListAll":
  41.                     foreach (var name in phonebook.OrderBy(x => x.Key))
  42.                     {
  43.                         Console.WriteLine($"{name.Key} -> {name.Value}");
  44.                     }
  45.                    
  46.                     break;
  47.  
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement