Advertisement
fbinnzhivko

Untitled

Sep 11th, 2016
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. class Phonebook
  4. {
  5.     static void Main()
  6.     {
  7.         string[] input = Console.ReadLine().Split();
  8.         Dictionary<string, string> phonebook = new Dictionary<string, string>();
  9.         while (input[0] != "END")
  10.         {
  11.             if (input[0] == "A")
  12.             {
  13.                 string name = input[1];
  14.                 string number = input[2];
  15.                 if (phonebook.ContainsKey(name))
  16.                 {
  17.                     phonebook[name] = number;
  18.                 }
  19.                 else
  20.                 {
  21.                     phonebook.Add(name, number);
  22.                 }
  23.             }
  24.             else
  25.             {
  26.                 string searchedName = input[1];
  27.                 if (phonebook.ContainsKey(searchedName))
  28.                 {
  29.                     Console.WriteLine($"{searchedName} -> {phonebook[searchedName]}");
  30.                 }
  31.                 else
  32.                 {
  33.                     Console.WriteLine($"Contact {searchedName} does not exist.");
  34.                 }
  35.             }
  36.             input = Console.ReadLine().Split();
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement