Advertisement
martinvalchev

Phonebook

Feb 16th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 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
  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.                         Console.WriteLine($"{funcion[1]} -> {phonebook[funcion[1]]}");
  35.                         break;
  36.                     }
  37.                     Console.WriteLine($"Contact {funcion[1]} does not exist.");
  38.                     break;
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement