Advertisement
Guest User

Untitled

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