Advertisement
reking12

Untitled

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