Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ListEx10Course
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> list = Console.ReadLine().Split(", ", StringSplitOptions.RemoveEmptyEntries).ToList();
- string commands;
- while ((commands = Console.ReadLine()) != "course start")
- {
- string[] text = commands.Split(':');
- if (text[0] == "Add" && !list.Contains(text[1]))
- {
- list.Add(text[1]);
- }
- else if (text[0] == "Insert" && !list.Contains(text[1]))
- {
- list.Insert(int.Parse(text[2]), text[1]);
- }
- else if (text[0] == "Remove" && list.Contains(text[1]))
- {
- list.Remove(text[1]);
- if (list.Contains($"{text[1]}-Exercise"))
- {
- list.Remove($"{text[1]}-Exercise");
- }
- }
- else if (text[0] == "Swap" && list.Contains(text[1]) && list.Contains(text[2]))
- {
- int firstLessonIndex = list.IndexOf(text[1]);
- int secondLessonIndex = list.IndexOf(text[2]);
- list[firstLessonIndex] = text[2];
- list[secondLessonIndex] = text[1];
- if (list.Contains($"{text[1]}-Exercise"))
- {
- list.Insert(secondLessonIndex + 1, $"{text[1]}-Exercise");
- list.RemoveAt(firstLessonIndex + 2);
- }
- if (list.Contains($"{text[2]}-Exercise"))
- {
- list.Insert(firstLessonIndex + 1, $"{text[2]}-Exercise");
- list.RemoveAt(secondLessonIndex + 2);
- }
- }
- else if (text[0] == "Exercise" && !list.Contains($"{text[1]}-Exercise"))
- {
- if (!list.Contains(text[1]))
- {
- list.Add(text[1]);
- list.Add($"{text[1]}-Exercise");
- }
- else
- {
- int indexOfLesson = list.IndexOf(text[1]);
- list.Insert(indexOfLesson + 1, $"{text[1]}-Exercise");
- }
- }
- }
- for (int i = 0; i < list.Count; i++)
- {
- Console.WriteLine("{0}.{1}", i + 1, list[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement