Advertisement
kalitarix

Course planning

Aug 17th, 2018
1,298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace CoursePlanning
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> lessons = Console.ReadLine().Split(", ").ToList();
  12.  
  13.             string input = Console.ReadLine();
  14.  
  15.             while (input != "course start")
  16.             {
  17.                 string[] data = input.Split(':');
  18.  
  19.                 string command = data[0];
  20.  
  21.                 if (command == "Add")
  22.                 {
  23.                     string title = data[1];
  24.  
  25.                     if (lessons.Contains(title) == false)
  26.                     {
  27.                         lessons.Add(title);
  28.                     }
  29.                 }
  30.                 else if (command == "Insert")
  31.                 {
  32.                     string title = data[1];
  33.                     int index = int.Parse(data[2]);
  34.  
  35.                     if (lessons.Contains(title) == false)
  36.                     {
  37.                         if (index >= 0 && index < lessons.Count)
  38.                         {
  39.                             lessons.Insert(index, title);
  40.                         }
  41.                     }
  42.                 }
  43.                 else if (command == "Remove")
  44.                 {
  45.                     string title = data[1];
  46.  
  47.                     if (lessons.Contains(title))
  48.                     {
  49.                         int index = lessons.IndexOf(title);
  50.  
  51.                         if (index + 1 < lessons.Count)
  52.                         {
  53.                             if (lessons[index + 1] == $"{title}-Exercise")
  54.                             {
  55.                                 lessons.RemoveRange(index, 2);
  56.                             }
  57.                             else
  58.                             {
  59.                                 lessons.Remove(title);
  60.                             }
  61.                         }
  62.                         else
  63.                         {
  64.                             lessons.Remove(title);
  65.                         }
  66.                     }
  67.                 }
  68.                 else if (command == "Swap")
  69.                 {
  70.                     string firstTitle = data[1];
  71.                     string secondTitle = data[2];
  72.  
  73.                     if (lessons.Contains(firstTitle) && lessons.Contains(secondTitle))
  74.                     {
  75.                         int firstTitleIndex = lessons.IndexOf(firstTitle);
  76.                         int secondTitleIndex = lessons.IndexOf(secondTitle);
  77.  
  78.                         lessons[firstTitleIndex] = secondTitle;
  79.                         lessons[secondTitleIndex] = firstTitle;
  80.  
  81.                         if (firstTitleIndex + 1 < lessons.Count && secondTitleIndex + 1 < lessons.Count)
  82.                         {
  83.                             if (lessons[firstTitleIndex + 1] == $"{firstTitle}-Exercise" && lessons[secondTitleIndex + 1] == $"{secondTitle}-Exercise")
  84.                             {
  85.                                 string temp = lessons[secondTitleIndex + 1];
  86.                                 lessons[secondTitleIndex + 1] = lessons[firstTitleIndex + 1];
  87.                                 lessons[firstTitleIndex + 1] = temp;
  88.                             }
  89.                             else if (lessons[firstTitleIndex + 1] == $"{firstTitle}-Exercise")
  90.                             {
  91.                                 lessons.Insert(secondTitleIndex + 1, lessons[firstTitleIndex + 1]);
  92.  
  93.                                 if (secondTitleIndex > firstTitleIndex)
  94.                                 {
  95.                                     lessons.RemoveAt(firstTitleIndex + 1);
  96.                                 }
  97.                                 else if (secondTitleIndex < firstTitleIndex)
  98.                                 {
  99.                                     lessons.RemoveAt(firstTitleIndex + 2);
  100.                                 }
  101.  
  102.                             }
  103.                             else if (lessons[secondTitleIndex + 1] == $"{secondTitle}-Exercise")
  104.                             {
  105.                                 lessons.Insert(firstTitleIndex + 1, lessons[secondTitleIndex + 1]);
  106.  
  107.                                 if (firstTitleIndex < secondTitleIndex)
  108.                                 {
  109.                                     lessons.RemoveAt(secondTitleIndex + 2);
  110.                                 }
  111.                                 else if (firstTitleIndex > secondTitleIndex)
  112.                                 {
  113.                                     lessons.RemoveAt(secondTitleIndex + 1);
  114.                                 }
  115.                             }
  116.                         }
  117.                         else if (firstTitleIndex + 1 < lessons.Count)
  118.                         {
  119.                             if (lessons[firstTitleIndex + 1] == $"{firstTitle}-Exercise")
  120.                             {
  121.                                 lessons.Insert(secondTitleIndex + 1, lessons[firstTitleIndex + 1]);
  122.  
  123.                                 if (secondTitleIndex > firstTitleIndex)
  124.                                 {
  125.                                     lessons.RemoveAt(firstTitleIndex + 1);
  126.                                 }
  127.                                 else if (secondTitleIndex < firstTitleIndex)
  128.                                 {
  129.                                     lessons.RemoveAt(firstTitleIndex + 2);
  130.                                 }
  131.                             }
  132.                         }
  133.                         else if (secondTitleIndex + 1 < lessons.Count)
  134.                         {
  135.                             if (lessons[secondTitleIndex + 1] == $"{secondTitle}-Exercise")
  136.                             {
  137.                                 lessons.Insert(firstTitleIndex + 1, lessons[secondTitleIndex + 1]);
  138.  
  139.                                 if (firstTitleIndex < secondTitleIndex)
  140.                                 {
  141.                                     lessons.RemoveAt(secondTitleIndex + 2);
  142.                                 }
  143.                                 else if (firstTitleIndex > secondTitleIndex)
  144.                                 {
  145.                                     lessons.RemoveAt(secondTitleIndex + 1);
  146.                                 }
  147.                             }
  148.                         }
  149.                     }
  150.                 }
  151.                 else if (command == "Exercise")
  152.                 {
  153.                     string title = data[1];
  154.  
  155.                     if (lessons.Contains(title))
  156.                     {
  157.                         int index = lessons.IndexOf(title);
  158.  
  159.                         if (index + 1 < lessons.Count)
  160.                         {
  161.                             if (lessons[index + 1] != $"{title}-Exercise")
  162.                             {
  163.                                 lessons.Insert(index + 1, $"{title}-Exercise");
  164.                             }
  165.                         }
  166.                         else
  167.                         {
  168.                             lessons.Add($"{title}-Exercise");
  169.                         }
  170.                     }
  171.                     else
  172.                     {
  173.                         lessons.Add(title);
  174.                         lessons.Add($"{title}-Exercise");
  175.                     }
  176.                 }
  177.  
  178.                 input = Console.ReadLine();
  179.             }
  180.  
  181.             for (int index = 0; index < lessons.Count; index++)
  182.             {
  183.                 Console.WriteLine($"{index + 1}.{lessons[index]}");
  184.             }
  185.         }
  186.     }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement