Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Contact_List
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> contacts = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList();
- var print = new List<string>();
- string[] commands = Console.ReadLine().Split(' ');
- while (true)
- {
- if (commands[0] == "Add")
- {
- string contactDetails = commands[1];
- int index = int.Parse(commands[2]);
- if (!contacts.Contains(contactDetails))
- {
- contacts.Add(contactDetails);
- }
- else if (index >= 0 && index < contacts.Count)
- {
- contacts.Insert(index, contactDetails);
- }
- }
- else if (commands[0] == "Remove")
- {
- int index = int.Parse(commands[1]);
- if (index >= 0 && index < contacts.Count)
- {
- contacts.RemoveAt(index);
- }
- }
- else if (commands[0] == "Export")
- {
- int startIndex = int.Parse(commands[1]);
- int count = int.Parse(commands[2]);
- if (count >= contacts.Count || count <= 0)
- {
- count = contacts.Count;
- }
- print = contacts.Skip(startIndex).Take(count).Select(x => x).ToList();
- Console.WriteLine(string.Join(' ', print));
- print.Clear();
- }
- else if (commands[1] == "Reversed")
- {
- for (int i = contacts.Count - 1; i >= 0; i++)
- {
- Console.WriteLine(string.Join(' ', i));
- break;
- }
- }
- else if (commands[1] == "Normal")
- {
- Console.WriteLine(string.Join(' ', contacts));
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement