Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- List<string> contacts = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- while (true)
- {
- string input = Console.ReadLine();
- string[] commandInput = input.Split(" ");
- string command = commandInput[0];
- switch (command)
- {
- case "Add":
- string contact = commandInput[1];
- int index = int.Parse(commandInput[2]);
- if (contacts.Contains(contact))
- {
- if (index >= 0 && index <= contacts.Count - 1)
- {
- contacts.Insert(index, contact);
- }
- }
- else
- {
- contacts.Add(contact);
- }
- break;
- case "Remove":
- index = int.Parse(commandInput[1]);
- if (index >= 0 && index <= contacts.Count - 1)
- {
- contacts.RemoveAt(index);
- }
- break;
- case "Export":
- int startIndex = int.Parse(commandInput[1]);
- int count = int.Parse(commandInput[2]);
- if (startIndex + count - 1 <= contacts.Count - 1)
- {
- for (int i = startIndex; i < count; i++)
- {
- Console.Write(contacts[i] + " ");
- }
- Console.WriteLine();
- }
- else
- {
- for (int i = startIndex; i < contacts.Count; i++)
- {
- Console.Write(contacts[i] + " ");
- }
- Console.WriteLine();
- }
- break;
- }
- if (command == "Print")
- {
- string subcommand = commandInput[1];
- if (subcommand == "Normal")
- {
- Console.WriteLine($"Contacts: {string.Join(" ", contacts)}");
- }
- else if (subcommand == "Reversed")
- {
- contacts.Reverse();
- Console.WriteLine($"Contacts: {string.Join(" ", contacts)}");
- }
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement