Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace SoftUniCourse
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- List<string> scheduleList = Console.ReadLine().Split(", ").ToList();
- string command = Console.ReadLine();
- while (command != "course start")
- {
- string[] commandArray = command.Split(':').ToArray();
- if (commandArray[0] == "Add")
- {
- Add(scheduleList, commandArray);
- }
- else if (commandArray[0] == "Insert")
- {
- Insert(scheduleList, commandArray);
- }
- else if (commandArray[0] == "Remove")
- {
- Remove(scheduleList, commandArray);
- }
- else if (commandArray[0] == "Swap")
- {
- string firstLesson = commandArray[1];
- string secondLesson = commandArray[2];
- if (scheduleList.Exists(x => x == firstLesson) && scheduleList.Exists(x => x == secondLesson))
- {
- Swap(scheduleList, firstLesson, secondLesson);
- }
- else
- {
- continue;
- }
- }
- else if (commandArray[0] == "Exercise")
- {
- string lessonTitle = commandArray[1];
- ExerciseCommand(scheduleList, lessonTitle);
- }
- command = Console.ReadLine();
- }
- int counter = 1;
- foreach (var item in scheduleList)
- {
- Console.WriteLine($"{counter}.{item}");
- counter++;
- }
- }
- private static void ExerciseCommand(List<string> scheduleList, string lessonTitle)
- {
- if (scheduleList.Contains(lessonTitle) && (scheduleList.Contains($"{lessonTitle}-Exercise") == false))
- {
- int indexOfLessonTitle = scheduleList.IndexOf(lessonTitle);
- scheduleList.Insert(indexOfLessonTitle + 1, $"{lessonTitle}-Exercise");
- }
- else if (scheduleList.Contains(lessonTitle) == false)
- {
- scheduleList.Add(lessonTitle);
- scheduleList.Add($"{lessonTitle}-Exercise");
- }
- }
- private static void Swap(List<string> scheduleList, string firstLesson, string secondLesson)
- {
- int firstIndex = scheduleList.IndexOf(firstLesson);
- int secondIndex = scheduleList.IndexOf(secondLesson);
- scheduleList[firstIndex] = secondLesson;
- scheduleList[secondIndex] = firstLesson;
- if (scheduleList.Contains($"{firstLesson}-Exercise"))
- {
- scheduleList.Remove($"{firstLesson}-Exercise");
- int indexOfFirstLesson = scheduleList.IndexOf(firstLesson);
- scheduleList.Insert(indexOfFirstLesson + 1, $"{firstLesson}-Exercise");
- }
- if (scheduleList.Contains($"{secondLesson}-Exercise"))
- {
- scheduleList.Remove($"{secondLesson}-Exercise");
- int indexOfSecondLesson = scheduleList.IndexOf(secondLesson);
- scheduleList.Insert(indexOfSecondLesson + 1, $"{secondLesson}-Exercise");
- }
- }
- private static void Remove(List<string> scheduleList, string[] commandArray)
- {
- string lessonTitle = commandArray[1];
- if (scheduleList.Contains(lessonTitle))
- {
- scheduleList.Remove(lessonTitle);
- }
- if (scheduleList.Contains($"{lessonTitle}-Exercise"))
- {
- scheduleList.Remove($"{lessonTitle}-Exercise");
- }
- }
- private static void Insert(List<string> scheduleList, string[] commandArray)
- {
- string lessonTitle = commandArray[1];
- int index = int.Parse(commandArray[2]);
- if (scheduleList.Contains(lessonTitle) == false && index >= 0 && index < scheduleList.Count)
- {
- scheduleList.Insert(index, lessonTitle);
- }
- }
- private static void Add(List<string> scheduleList, string[] commandArray)
- {
- string lessonTitle = commandArray[1];
- if (scheduleList.Contains(lessonTitle) == false)
- {
- scheduleList.Add(lessonTitle);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment