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