Advertisement
NadyaMisheva

telefonen ykazatel

Feb 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. public class Program
  5. {
  6.     public static void Main()
  7.     {
  8.         Dictionary<string, string> phonebook = new Dictionary<string, string>();
  9.         while(true)
  10.         {
  11.             Console.WriteLine("1. Изпечатай целия теленонен указател");
  12.             Console.WriteLine("2. Добави номер");
  13.             Console.WriteLine("3. Изтрий номер");
  14.             Console.WriteLine("4. Потърси номер");
  15.             Console.WriteLine("5. Излез");
  16.             string common = Console.ReadLine();
  17.             if(common == "1" )
  18.             {
  19.                 foreach(var el in phonebook)
  20.                 {
  21.                     Console.WriteLine("{0} -> {1}", el.Key, el.Value);
  22.                 }
  23.             }
  24.             else if(common == "2")
  25.             {
  26.                 Console.Write("Въведи име и номер");
  27.                 string[] input  = Console.ReadLine().Split(' ');
  28.                 {
  29.                     phonebook[input[0]] = input[1];
  30.                 }
  31.             }
  32.             else if(common == "3")
  33.             {
  34.                 string name = Console.ReadLine();
  35.                 if(phonebook.ContainsKey(name))
  36.                    {
  37.                      phonebook.Remove(name);
  38.                       Console.WriteLine("Името е успешно изтрито");  
  39.                    }
  40.                  else
  41.                    {
  42.                      Console.WriteLine("Това име не съществува");  
  43.                    }
  44.             }
  45.             else if(common == "4")
  46.             {
  47.                 string name = Console.ReadLine();
  48.                 if(phonebook.ContainsKey(name))
  49.                 {
  50.                      Console.WriteLine(phonebook[name]);  
  51.                 }
  52.                 else
  53.                 {
  54.                      Console.WriteLine("Този номер не съществува");  
  55.                 }
  56.             }
  57.             else if(common == "5")
  58.             {
  59.                 break;
  60.             }
  61.             Console.ReadLine();
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement