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