Advertisement
gospod1978

List-Ex/SoftUni Course Planning

Oct 23rd, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace _02._Problem
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             var lessons = Console.ReadLine()
  11.                 .Split(", ", StringSplitOptions.RemoveEmptyEntries)
  12.                 .ToList();
  13.  
  14.             while (true)
  15.             {
  16.                 var command = Console.ReadLine().Split(':', StringSplitOptions.RemoveEmptyEntries).ToArray();
  17.                 var command1 = command[0];
  18.  
  19.                 if (command1 == "course start")
  20.                 {
  21.                     break;
  22.                 }
  23.  
  24.                 if (command1 == "Add")
  25.                 {
  26.                     if (!lessons.Contains(command[1]))
  27.                     {
  28.                         lessons.Add(command[1]);
  29.                     }
  30.                 }
  31.                 else if (command1 == "Insert")
  32.                 {
  33.                     if (!lessons.Contains(command[1]))
  34.                     {
  35.                         if (Convert.ToInt32(command[2]) < lessons.Count &&
  36.                             Convert.ToInt32(command[2]) >= 0)
  37.                         {
  38.                             lessons.Insert(Convert.ToInt32(command[2]), command[1]);
  39.                         }
  40.                     }
  41.                 }
  42.                 else if (command1 == "Remove")
  43.                 {
  44.                     lessons.Remove(command[1]);
  45.                     lessons.Remove($"{command[1]}-Exercise");
  46.                 }
  47.                 else if (command1 == "Swap")
  48.                 {
  49.                     string lessonTitle1 = command[1];
  50.                     string lessonTitle2 = command[2];
  51.                     int index1 = lessons.IndexOf(lessonTitle1);
  52.                     int index2 = lessons.IndexOf(lessonTitle2);
  53.  
  54.                     if (index1 != -1 && index2 != -1)
  55.                     {
  56.                         lessons[index1] = lessonTitle2;
  57.                         lessons[index2] = lessonTitle1;
  58.  
  59.                         if (index1 + 1 < lessons.Count && lessons[index1 + 1] == $"{lessonTitle1}-Exercise")
  60.                         {
  61.                             lessons.RemoveAt(index1 + 1);
  62.                             index1 = lessons.IndexOf(lessonTitle1);
  63.                             lessons.Insert(index1 + 1, $"{lessonTitle1}-Exercise");
  64.                         }
  65.  
  66.                         if (index2 + 1 < lessons.Count && lessons[index2 + 1] == $"{lessonTitle2}-Exercise")
  67.                         {
  68.                             lessons.RemoveAt(index2 + 1);
  69.                             index2 = lessons.IndexOf(lessonTitle2);
  70.                             lessons.Insert(index2 + 1, $"{lessonTitle2}-Exercise");
  71.                         }
  72.                     }
  73.                 }
  74.                 else if (command1 == "Exercise")
  75.                 {
  76.                     int index = lessons.IndexOf(command[1]);
  77.  
  78.                     if (lessons.Contains(command[1]) && !lessons.Contains($"{command[1]}-Exercise"))
  79.                     {
  80.                         lessons.Insert(index + 1, $"{command[1]}-Exercise");
  81.                     }
  82.                     else if (!lessons.Contains(command[1]))
  83.                     {
  84.                         lessons.Add(command[1]);
  85.                         lessons.Add($"{command[1]}-Exercise");
  86.                     }
  87.                 }
  88.             }
  89.             for (int i = 0; i < lessons.Count; i++)
  90.             {
  91.                 Console.WriteLine($"{i + 1}.{lessons[i]}");
  92.             }
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement