Advertisement
alexbancheva

Krassy_Contact_List

Jun 21st, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Krassy_Contact_List
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> contact = Console.ReadLine().Split(" ").ToList();
  12.  
  13.             string comand = "";
  14.  
  15.             while (true)
  16.             {
  17.                 comand = Console.ReadLine();
  18.                 string[] comandInArr = comand.Split(" ").ToArray();
  19.  
  20.                 if (comandInArr[0] == "Add")
  21.                 {
  22.                     string contactName = comandInArr[1];
  23.  
  24.                     if (!contact.Contains(contactName))
  25.                     {
  26.                         contact.Add(contactName);
  27.                     }
  28.                     else if (contact.Contains(contactName))
  29.                     {
  30.                         int index = int.Parse(comandInArr[2]);
  31.                         if (contact.Count > index && index > 0)
  32.                         {
  33.                             contact.Insert(index, contactName);
  34.                         }
  35.  
  36.                     }
  37.                 }
  38.                 else if (comandInArr[0] == "Remove")
  39.                 {
  40.                     int index = int.Parse(comandInArr[1]);
  41.                     if (contact.Count > index && index > 0)
  42.                     {
  43.                         contact.RemoveAt(index);
  44.                     }
  45.                 }
  46.                 else if (comandInArr[0] == "Export")
  47.                 {
  48.                     int startIndex = int.Parse(comandInArr[1]);
  49.                     int countContacta = int.Parse(comandInArr[2]);
  50.                     if (contact.Count > startIndex && contact.Count >= countContacta)
  51.                     {
  52.                         for (int i = startIndex; i < countContacta; i++)
  53.                         {
  54.  
  55.                             Console.Write(contact[i] + " ");
  56.                         }
  57.                         Console.WriteLine();
  58.                     }
  59.                     else if (contact.Count > startIndex && contact.Count < countContacta)
  60.                     {
  61.                         for (int i = startIndex; i < contact.Count; i++)
  62.                         {
  63.  
  64.                             Console.Write(contact[i] + " ");
  65.                         }
  66.                         Console.WriteLine();
  67.                     }
  68.  
  69.                 }
  70.                 else if (comandInArr[0] == "Print")
  71.                 {
  72.                     string nomralOrReverse = comandInArr[1];
  73.                     if (nomralOrReverse == "Normal")
  74.                     {
  75.                         //for (int i = 0; i < contact.Count; i++)
  76.                         //{
  77.  
  78.                         //    Console.Write(string.Join("  ", contact[i]));
  79.                         //}
  80.                         Console.WriteLine($"Contacts: {string.Join(" ", contact)}");
  81.                         break;
  82.                     }
  83.                     else if (nomralOrReverse == "Reversed")
  84.                     {
  85.                         //for (int i = contact.Count - 1; i >= 0; i--)
  86.                         //{
  87.  
  88.                         //    Console.Write(string.Join("  ", contact[i]));
  89.                         //}
  90.                         //break;
  91.                         contact.Reverse();
  92.                         Console.WriteLine($"Contacts: {string.Join(" ", contact)} ");
  93.                         break;
  94.                     }
  95.                 }
  96.  
  97.             }
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement