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