Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace SoftUniCoursePlanning
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- List<string> schedule = Console.ReadLine()
- .Split(", ", StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- string imput = Console.ReadLine();
- while (imput != "course start")
- {
- string[] command = imput
- .Split(':')
- .ToArray();
- if (command[0] == "Add")
- {
- if(!schedule.Contains(command[1]))
- {
- schedule.Add(command[1]);
- }
- }
- else if (command[0] == "Insert")
- {
- if (!schedule.Contains(command[1]))
- {
- if(int.Parse(command[2]) >= 0 && int.Parse(command[2]) < schedule.Count)
- {
- schedule.Insert(int.Parse(command[2]), command[1]);
- }
- }
- }
- else if (command[0] == "Remove")
- {
- if (schedule.Contains(command[1]))
- {
- schedule.Remove(command[1]);
- }
- string exercise = command[1] + "-Exercise";
- if (schedule.Contains(exercise))
- {
- schedule.Remove(exercise);
- }
- }
- else if (command[0] == "Exercise")
- {
- if (schedule.Contains(command[1]))
- {
- int indexOfLesson = schedule.IndexOf(command[1]);
- int indexOfExercise = indexOfLesson + 1;
- string addition = command[1] + "-Exercise";
- schedule.Insert(indexOfExercise, addition);
- }
- else
- {
- string addition = command[1] + "-Exercise";
- schedule.Add(command[1]);
- schedule.Add(addition);
- }
- }
- else if (command[0] == "Swap")
- {
- if (schedule.Contains(command[1]) && schedule.Contains(command[2]))
- {
- string firstExercise = command[1] + "-Exercise";
- string secondExercise = command[2] + "-Exercise";
- int indexOfFirst = schedule.IndexOf(command[1]);
- string firstText = command[1];
- int indexOfSecond = schedule.IndexOf(command[2]);
- string secondtext = command[2];
- int originalIndexOfFirst = indexOfFirst;
- int originalIndexOfSecond = indexOfSecond;
- if(indexOfFirst > indexOfSecond)
- {
- indexOfFirst = originalIndexOfSecond;
- firstExercise = command[2] + "-Exercise";
- firstText = command[2];
- secondtext = command[1];
- indexOfSecond = originalIndexOfFirst;
- secondExercise = command[1] + "-Exercise";
- }
- if (!schedule.Contains(firstExercise) && !schedule.Contains(secondExercise))
- {
- schedule.RemoveAt(indexOfFirst);
- schedule.Insert(indexOfFirst, secondtext);
- schedule.RemoveAt(indexOfSecond);
- schedule.Insert(indexOfSecond, firstText);
- }
- else if (schedule.Contains(firstExercise) && !schedule.Contains(secondExercise))
- {
- schedule.RemoveAt(indexOfFirst);
- schedule.RemoveAt(indexOfFirst);
- schedule.Remove(secondtext);
- schedule.Insert(indexOfFirst, secondtext);
- if (indexOfSecond >= schedule.Count)
- {
- schedule.Add(firstText);
- schedule.Add(firstText + "-Exercise");
- }
- else
- {
- schedule.Insert(indexOfSecond, firstText + "-Exercise");
- schedule.Insert(indexOfSecond, firstText);
- }
- }
- else if (!schedule.Contains(firstExercise) && schedule.Contains(secondExercise))
- {
- schedule.RemoveAt(indexOfFirst);
- schedule.Insert(indexOfFirst, secondtext);
- schedule.Insert(indexOfFirst + 1, secondtext + "-Exercise");
- schedule.RemoveAt(indexOfSecond + 1);
- schedule.RemoveAt(indexOfSecond + 1);
- schedule.Insert(indexOfSecond +1, firstText);
- }
- else if (schedule.Contains(firstExercise) && schedule.Contains(secondExercise))
- {
- schedule.RemoveAt(indexOfFirst);
- schedule.RemoveAt(indexOfFirst);
- schedule.Insert(indexOfFirst, secondtext + "-Exercise");
- schedule.Insert(indexOfFirst, secondtext);
- schedule.RemoveAt(indexOfSecond);
- schedule.RemoveAt(indexOfSecond);
- schedule.Insert(indexOfSecond, firstText + "-Exercise");
- schedule.Insert(indexOfSecond, firstText);
- }
- }
- }
- imput = Console.ReadLine();
- }
- for (int i = 1; i <= schedule.Count; i++)
- {
- Console.WriteLine($"{i}.{schedule[i-1]}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement