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