Advertisement
Guest User

Phonebook

a guest
Sep 11th, 2016
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class PhoneBook
  6. {
  7.     static void Main()
  8.     {
  9.         string command = Console.ReadLine(); // read the command
  10.        
  11.         Dictionary<string, string> phonebook = new Dictionary<string, string>(); // make a dictionary for the phonebook
  12.  
  13.        
  14.         while (command != "END") // check
  15.         {
  16.             string[] splitedCommands = command.Split(' ').ToArray(); // split the commands
  17.  
  18.             if (splitedCommands[0] == "S")
  19.             {
  20.                 if (!phonebook.ContainsKey(splitedCommands[1]))
  21.                 {
  22.                     Console.WriteLine("Contact {0} does not exist.", splitedCommands[1]);
  23.                 }
  24.                 else
  25.                 {
  26.                     Console.WriteLine("{0} -> {1}", splitedCommands[1], phonebook[splitedCommands[1]]);
  27.                 }
  28.             }
  29.             else
  30.             {
  31.                 phonebook[splitedCommands[1]] = splitedCommands[2];
  32.             }
  33.  
  34.             command = Console.ReadLine(); // read the command again
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement