Advertisement
Dimitar46

Course Planning

Oct 19th, 2021
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ListEx10Course
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> list = Console.ReadLine().Split(", ", StringSplitOptions.RemoveEmptyEntries).ToList();
  12.             string commands;
  13.  
  14.             while ((commands = Console.ReadLine()) != "course start")
  15.             {
  16.                 string[] text = commands.Split(':');
  17.  
  18.  
  19.                 if (text[0] == "Add" && !list.Contains(text[1]))
  20.                 {
  21.                     list.Add(text[1]);
  22.                 }
  23.                 else if (text[0] == "Insert" && !list.Contains(text[1]))
  24.                 {
  25.  
  26.                     list.Insert(int.Parse(text[2]), text[1]);
  27.  
  28.  
  29.                 }
  30.                 else if (text[0] == "Remove" && list.Contains(text[1]))
  31.                 {
  32.                     list.Remove(text[1]);
  33.                     if (list.Contains($"{text[1]}-Exercise"))
  34.                     {
  35.                         list.Remove($"{text[1]}-Exercise");
  36.                     }
  37.  
  38.                 }
  39.  
  40.                 else if (text[0] == "Swap" && list.Contains(text[1]) && list.Contains(text[2]))
  41.                 {
  42.                     int firstLessonIndex = list.IndexOf(text[1]);
  43.                     int secondLessonIndex = list.IndexOf(text[2]);
  44.                     list[firstLessonIndex] = text[2];
  45.                     list[secondLessonIndex] = text[1];
  46.                     if (list.Contains($"{text[1]}-Exercise"))
  47.                     {
  48.                         list.Insert(secondLessonIndex + 1, $"{text[1]}-Exercise");
  49.                         list.RemoveAt(firstLessonIndex + 2);
  50.                     }
  51.                     if (list.Contains($"{text[2]}-Exercise"))
  52.                     {
  53.                         list.Insert(firstLessonIndex + 1, $"{text[2]}-Exercise");
  54.                         list.RemoveAt(secondLessonIndex + 2);
  55.                     }
  56.                 }
  57.                 else if (text[0] == "Exercise" && !list.Contains($"{text[1]}-Exercise"))
  58.                 {
  59.                     if (!list.Contains(text[1]))
  60.                     {
  61.                         list.Add(text[1]);
  62.                         list.Add($"{text[1]}-Exercise");
  63.                     }
  64.                     else
  65.                     {
  66.                         int indexOfLesson = list.IndexOf(text[1]);
  67.                         list.Insert(indexOfLesson + 1, $"{text[1]}-Exercise");
  68.                     }
  69.                 }
  70.  
  71.  
  72.  
  73.             }
  74.             for (int i = 0; i < list.Count; i++)
  75.             {
  76.                 Console.WriteLine("{0}.{1}", i + 1, list[i]);
  77.             }
  78.         }
  79.     }
  80. }
  81.  
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement