Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03._Phonebook
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string[] inputs = Console.ReadLine().Split(' ').ToArray();
  12.             var phoneBook = new SortedDictionary<string, string>();
  13.             var output = new List<string>();
  14.             bool tmp = false;
  15.  
  16.             while (inputs[0] != "END")
  17.             {
  18.                 if (inputs[0] == "A")
  19.                 {
  20.                     if (phoneBook.ContainsKey(inputs[1]))
  21.                     {
  22.                         phoneBook[inputs[1]] = inputs[2];
  23.                     }
  24.                     else
  25.                     {
  26.                         phoneBook.Add(inputs[1], inputs[2]);
  27.                     }
  28.                 }
  29.                 else if (inputs[0] == "S")
  30.  
  31.                     if (phoneBook.ContainsKey(inputs[1]))
  32.                     {
  33.                         output.Add(inputs[1] + " -> " + phoneBook[inputs[1]]);
  34.                     }
  35.                     else
  36.                     {
  37.                         output.Add("Contact " + inputs[1] + " does not exist.");
  38.                         output.Remove(inputs[1]);
  39.                     }
  40.                 else if (inputs[0] == "ListAll")
  41.                 {
  42.                     tmp = true;
  43.                 }
  44.  
  45.                 inputs = Console.ReadLine().Split(' ').ToArray();
  46.             }
  47.  
  48.             Console.WriteLine(string.Join("\n", output));
  49.             if (tmp)
  50.             {
  51.                 foreach (var item in phoneBook)
  52.                 {
  53.                     Console.WriteLine($"{item.Key} -> {item.Value}");
  54.                 }
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement