Advertisement
FidoDidoo100

Phonebook

Feb 2nd, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Dictionaries__Lambda__Linq_Exercise
  5. {
  6.     public class PhoneBook
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             var phonebook = new SortedDictionary<string, string>();
  11.  
  12.  
  13.             var input = Console.ReadLine().Split().ToList();
  14.  
  15.             while (input[0]!="END")
  16.             {
  17.                
  18.                 if (input[0] == "A")
  19.                 {
  20.                     phonebook[input[1]] = input[2];
  21.                 }
  22.                 else if (input[0] == "S")
  23.                 {
  24.                     if (phonebook.ContainsKey(input[1]))
  25.                     {
  26.                         Console.WriteLine($"{input[1]} -> {phonebook[input[1]].ToString()}");
  27.                     }
  28.                     else
  29.                     {
  30.                         Console.WriteLine($"Contact {input[1]} does not exist.");
  31.                     }
  32.                 }
  33.                 input = Console.ReadLine().Split().ToList();
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement