Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace P10SoftUni_Course_Planning
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> LessonsAndExercises = Console.ReadLine().
- Split(", ",StringSplitOptions.RemoveEmptyEntries).
- ToList();
- while (true)
- {
- List<string> commands = Console.ReadLine().
- Split(':',StringSplitOptions.RemoveEmptyEntries).
- ToList();
- if (commands[0] == "course start")
- {
- break;
- }
- if (commands[0] == "Add")
- {
- if (!LessonsAndExercises.Contains(commands[1]))
- {
- LessonsAndExercises.Add(commands[1]);
- }
- }
- else if (commands[0] == "Insert")
- {
- if (!LessonsAndExercises.Contains(commands[1]))
- {
- if (Convert.ToInt32(commands[2]) < LessonsAndExercises.Count &&
- Convert.ToInt32(commands[2]) >= 0)
- {
- LessonsAndExercises.Insert(int.Parse(commands[2]), commands[1]);
- }
- }
- }
- else if (commands[0] == "Remove")
- {
- if (LessonsAndExercises.Contains(commands[1]))
- {
- LessonsAndExercises.Remove(commands[1]);
- LessonsAndExercises.Remove($"{commands[1]}-Exercise");
- }
- }
- else if (commands[0] == "Swap")
- {
- if (LessonsAndExercises.Contains(commands[1]) && LessonsAndExercises.Contains(commands[2]))
- {
- string command1 = commands[1];
- string command2 = commands[2];
- int index1 = LessonsAndExercises.IndexOf(commands[1]);
- int index2 = LessonsAndExercises.IndexOf(commands[2]);
- if (index1 != -1 && index2 != -1)
- {
- LessonsAndExercises[index1] = command2;
- LessonsAndExercises[index2] = command1;
- if (index1 + 1 < LessonsAndExercises.Count && LessonsAndExercises[index1 + 1] == $"{command1}-Exercise")
- {
- LessonsAndExercises.RemoveAt(index1 + 1);
- index1 = LessonsAndExercises.IndexOf(command1);
- LessonsAndExercises.Insert(index1 + 1, $"{command1}-Exercise");
- }
- if (index2 + 1 < LessonsAndExercises.Count && LessonsAndExercises[index2 + 1] == $"{command2}-Exercise")
- {
- LessonsAndExercises.RemoveAt(index2 + 1);
- index2 = LessonsAndExercises.IndexOf(command2);
- LessonsAndExercises.Insert(index2 + 1, $"{command2}-Exercise");
- }
- }
- }
- }
- else if (commands[0] == "Exercise")
- {
- int index = LessonsAndExercises.IndexOf(commands[1]);
- if (LessonsAndExercises.Contains(commands[1]) && !LessonsAndExercises.Contains($"{commands[1]}-Exercise"))
- {
- LessonsAndExercises.Insert(index + 1,
- $"{commands[1]}-Exercise");
- }
- else if (!LessonsAndExercises.Contains(commands[1]))
- {
- LessonsAndExercises.Add(commands[1]);
- LessonsAndExercises.Add($"{commands[1]}-Exercise");
- }
- }
- // Console.WriteLine(string.Join("\n",LessonsAndExercises));
- }
- for (int i = 0; i < LessonsAndExercises.Count; i++)
- {
- Console.WriteLine($"{i + 1}.{LessonsAndExercises[i]}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement