Advertisement
Guest User

Untitled

a guest
Jul 4th, 2019
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03._Problem
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.  
  12.             var list = Console.ReadLine()
  13.                 .Split(' ')
  14.                 .Where(x => !string.IsNullOrWhiteSpace(x))
  15.                 .ToList();
  16.             var print = new List<string>();
  17.  
  18.             string input;
  19.  
  20.             while (!(input = Console.ReadLine()).Contains("Print"))
  21.             {
  22.                 string command = input.Split(" ")[0];
  23.  
  24.                 if (command == "Add")
  25.                 {
  26.                     string contact = input.Split(" ")[1];
  27.                     int index = int.Parse(input.Split(" ")[2]);
  28.  
  29.                     if (!list.Contains(contact))
  30.                     {
  31.                         list.Add(contact);
  32.                     }
  33.                     else if (index >= 0 && index < list.Count)
  34.                     {
  35.                         list.Insert(index, contact);
  36.                     }
  37.  
  38.                 }
  39.                 else if (command == "Remove")
  40.                 {
  41.                     int index = int.Parse(input.Split(" ")[1]);
  42.  
  43.                     if (index >= 0 && index < list.Count)
  44.                     {
  45.                         list.RemoveAt(index);
  46.                     }
  47.                 }
  48.                 else if (command == "Export")
  49.                 {
  50.                     int startIndex = int.Parse(input.Split(" ")[1]);
  51.                     int count = int.Parse(input.Split(" ")[2]);
  52.  
  53.                     if (startIndex >= 0 && startIndex < list.Count() && count > 0)
  54.                     {
  55.                         if (count >= list.Count || count <= 0)
  56.                         {
  57.                             count = list.Count;
  58.                         }
  59.                         print = list.Skip(startIndex).Take(count).Select(x => x).ToList();
  60.                         //for (int i = startIndex; i < count; i++)
  61.                         //{
  62.                             //print.Add(list[i]);
  63.                         //}
  64.                         Console.WriteLine(string.Join(" ", print));
  65.                         print.Clear();
  66.                     }
  67.                 }
  68.  
  69.             }
  70.             if (input.Split(" ")[1] == "Reversed")
  71.             {
  72.                 list.Reverse();
  73.             }
  74.             Console.WriteLine($"Contacts: {string.Join(" ", list)}");
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement