Advertisement
silvana1303

softubi course planning

Jun 21st, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.67 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Numerics;
  5.  
  6. namespace exampreparation
  7. {
  8.     class exam
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<string> schedule = Console.ReadLine().Split(", ").ToList();
  13.  
  14.             string[] command = Console.ReadLine().Split(':').ToArray();
  15.  
  16.             while (command[0] != "course start")
  17.             {
  18.                 if (command[0] == "Add")
  19.                 {
  20.                     if (!schedule.Contains(command[1]))
  21.                     {
  22.                         schedule.Add(command[1]);
  23.                     }
  24.                 }
  25.                 if (command[0] == "Insert")
  26.                 {
  27.                     int index = int.Parse(command[2]);
  28.  
  29.                     if (!schedule.Contains(command[1]))
  30.                     {
  31.                         schedule.Insert(index, command[1]);
  32.                     }
  33.                 }
  34.                 if (command[0] == "Remove")
  35.                 {
  36.                     if (schedule.Contains(command[1]))
  37.                     {
  38.                         schedule.Remove(command[1]);
  39.  
  40.                         if (schedule.Contains($"{command[1]}-Exercise"))
  41.                         {
  42.                             schedule.Remove($"{command[1]}-Exercise");
  43.                         }
  44.                  
  45.                     }
  46.                     if (schedule.Contains($"{command[1]}-Exercise"))
  47.                     {
  48.                         schedule.Remove($"{command[1]}-Exercise");
  49.                     }
  50.                 }
  51.                 if (command[0] == "Swap")
  52.                 {
  53.                     if ((schedule.Contains(command[1]) && schedule.Contains(command[2])))
  54.                     {
  55.                         int index1 = schedule.IndexOf(command[1]);
  56.                         int index2 = schedule.IndexOf(command[2]);
  57.  
  58.                         schedule[index1] = command[2];
  59.                         schedule[index2] = command[1];
  60.  
  61.                         if (schedule.Contains($"{command[1]}-Exercise") && schedule.Contains($"{command[2]}-Exercise"))
  62.                         {
  63.                             if (index1 + 1 < schedule.Count && index2 + 1 < schedule.Count)
  64.                             {
  65.                                 int indEx1 = schedule.IndexOf($"{command[2]}-Exercise");
  66.                                 schedule.RemoveAt(indEx1);
  67.                                 int indEx2 = schedule.IndexOf($"{command[1]}-Exercise");
  68.                                 schedule.RemoveAt(indEx2);
  69.                                 schedule.Insert(index1 + 1, $"{command[2]}-Exercise");
  70.                                 schedule.Insert(index2 + 1, $"{command[1]}-Exercise");
  71.                             }
  72.                         }
  73.                         else if (schedule.Contains($"{command[1]}-Exercise"))
  74.                         {
  75.                             if (index2 + 1 < schedule.Count)
  76.                             {
  77.                                 int indEx = schedule.IndexOf($"{command[1]}-Exercise");
  78.                                 schedule.RemoveAt(indEx);
  79.                                 schedule.Insert(index2 + 1, $"{command[1]}-Exercise");
  80.                             }
  81.                         }
  82.                         else if (schedule.Contains($"{command[2]}-Exercise"))
  83.                         {
  84.                             if (index1 + 1 < schedule.Count)
  85.                             {
  86.                                 int indEx = schedule.IndexOf($"{command[2]}-Exercise");
  87.                                 schedule.RemoveAt(indEx);
  88.                                 schedule.Insert(index1 + 1, $"{command[2]}-Exercise");
  89.  
  90.                             }
  91.                         }
  92.                     }
  93.                 }
  94.                 if (command[0] == "Exercise")
  95.                 {
  96.                     string exercise = command[1] + '-' + "Exercise";
  97.                     if (schedule.Contains(command[1]) && (!schedule.Contains(command[0])))
  98.                     {
  99.                         int index = schedule.IndexOf(command[1]) + 1;
  100.                         schedule.Insert(index, exercise);
  101.                     }
  102.                     else if (!(schedule.Contains(command[0]) && schedule.Contains(command[1])))
  103.                     {
  104.                         schedule.Add(command[1]);
  105.                         schedule.Add(exercise);
  106.                     }
  107.                 }
  108.  
  109.                 command = Console.ReadLine().Split(':').ToArray();
  110.             }
  111.  
  112.             for (int i = 0; i < schedule.Count; i++)
  113.             {
  114.                 Console.WriteLine($"{i + 1}.{schedule[i]}");
  115.             }
  116.         }
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement