Advertisement
bacco

Phonebook

Jun 8th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6. namespace Phonebook
  7. {
  8.     class MainClass
  9.     {
  10.         public static void Main(string[] args)
  11.         {
  12.             Dictionary<string, string> phonebook = new Dictionary<string, string>();
  13.  
  14.             string[] input = Console.ReadLine()
  15.                                     .Split(' ')
  16.                                     .ToArray();
  17.  
  18.             while (input[0] != "END")
  19.             {
  20.                 if (input[0] == "A")
  21.                 {
  22.                     if (!phonebook.ContainsKey(input[1]))
  23.                     {
  24.                         phonebook.Add(input[1], input[2]);
  25.                     }
  26.                     else
  27.                     {
  28.                         phonebook[input[1]] = input[2];
  29.                     }
  30.                 }
  31.                 else if (input[0] == "S")
  32.                 {
  33.                     if (!phonebook.ContainsKey(input[1]))
  34.                     {
  35.                         Console.WriteLine($"Contact {input[1]} does not exist.");
  36.                     }
  37.                     else
  38.                     {
  39.                         Console.WriteLine($"{input[1]} -> {phonebook[input[1]]}");
  40.                     }
  41.                 }
  42.  
  43.                  input = Console.ReadLine()
  44.                                     .Split(' ')
  45.                                     .ToArray();
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement