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