Advertisement
Vladimir76

phonebook

Feb 6th, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 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 Dictionary<string, string> phonebook = new Dictionary<string, string>();
  12.  
  13.         static void Main()
  14.         {
  15.             string arr = Console.ReadLine();
  16.             List<string> arrInput = arr.Trim().Split(' ').ToList();
  17.  
  18.             while (arr!="END")
  19.             {
  20.                 arrInput = arr.Trim().Split(' ').ToList();
  21.                 if (arrInput[0].Equals("A"))
  22.                 {
  23.                     if (phonebook.ContainsKey(arrInput[1]))
  24.                     {
  25.                         phonebook[arrInput[1]] = arrInput[2];
  26.                     }
  27.                     else
  28.                     {
  29.                         phonebook.Add(arrInput[1], arrInput[2]);
  30.                     }
  31.                 }
  32.                 if (arrInput[0].Equals("S"))
  33.                 {
  34.                     if (phonebook.ContainsKey(arrInput[1]))
  35.                     {
  36.                         Console.WriteLine("{0} -> {1}", arrInput[1], phonebook[arrInput[1]]);
  37.                     }
  38.                     else
  39.                     {
  40.                         Console.WriteLine("Contact {0} does not exist.", arrInput[1]);
  41.                     }
  42.                 }
  43.                 arr = Console.ReadLine();
  44.                 if (arr == "END")
  45.                 {
  46.                     break;
  47.                 }
  48.             }
  49.                    
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement