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