Advertisement
GabrielDas

Untitled

Feb 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. using System;
  2.  
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace SoftUniCoursePlanning
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. List<string> courseSchedule = Console.ReadLine().Split(", ").ToList();
  15.  
  16. while (true)
  17. {
  18. string command = Console.ReadLine();
  19.  
  20. if (command == "course start")
  21. {
  22. break;
  23. }
  24.  
  25. ModifySchedule(command, courseSchedule);
  26. }
  27.  
  28. foreach (var item in courseSchedule)
  29. {
  30. Console.WriteLine($"{courseSchedule.IndexOf(item)+1}.{item}");
  31. }
  32. }
  33.  
  34. private static void ModifySchedule(string command, List<string> courseSchedule)
  35. {
  36. string[] tokens = command.Split(':');
  37. if (tokens[0] == "Add")
  38. {
  39. string lesson = tokens[1];
  40. if (!courseSchedule.Contains(lesson))
  41. {
  42. courseSchedule.Add(lesson);
  43. }
  44. }
  45. else if (tokens[0] == "Insert")
  46. {
  47. string lesson = tokens[1];
  48. int index = int.Parse(tokens[2]);
  49.  
  50. if (!courseSchedule.Contains(lesson))
  51. {
  52. courseSchedule.Insert(index, lesson);
  53. }
  54. }
  55. else if (tokens[0] == "Remove")
  56. {
  57. string lesson = tokens[1];
  58. string exercise = lesson + "-Exercise";
  59.  
  60. if (courseSchedule.Contains(lesson))
  61. {
  62. courseSchedule.Remove(lesson);
  63.  
  64. if (courseSchedule.Contains(exercise))
  65. {
  66. courseSchedule.Remove(exercise);
  67. }
  68. }
  69. }
  70. else if (tokens[0] == "Swap")
  71. {
  72. string firstLesson = tokens[1];
  73. string secondLesson = tokens[2];
  74.  
  75. Swap(firstLesson, secondLesson, courseSchedule);
  76.  
  77. }
  78. else if (tokens[0] == "Exercise")
  79. {
  80. string exercise = tokens[1] + "-Exercise";
  81.  
  82. if (courseSchedule.Contains(tokens[1]) && !courseSchedule.Contains(exercise))
  83. {
  84. int index = courseSchedule.IndexOf(tokens[1]);
  85.  
  86. if (index == courseSchedule.Count - 1)
  87. {
  88. courseSchedule.Add(exercise);
  89. }
  90. else
  91. {
  92. courseSchedule.Insert(index + 1, exercise);
  93. }
  94. }
  95. else if (!courseSchedule.Contains(tokens[1]))
  96. {
  97.  
  98. courseSchedule.Add(tokens[1]);
  99. courseSchedule.Add(exercise);
  100. }
  101. }
  102. }
  103.  
  104. private static void Swap(string firstLesson, string secondLesson, List<string> courseSchedule)
  105. {
  106.  
  107.  
  108. int firstIndex = courseSchedule.IndexOf(firstLesson);
  109. int secondIndex = courseSchedule.IndexOf(secondLesson);
  110. string firstExercise = firstLesson + "-Exercise";
  111. string secondExercise = secondLesson + "-Exercise";
  112. string temp = "";
  113. string tempEx = "";
  114.  
  115. if (courseSchedule.Contains(firstLesson) && courseSchedule.Contains(secondLesson))
  116. {
  117. if (courseSchedule.Contains(firstExercise) || courseSchedule.Contains(secondExercise))
  118. {
  119.  
  120. temp = courseSchedule[firstIndex];
  121. courseSchedule[firstIndex] = courseSchedule[secondIndex];
  122. courseSchedule[secondIndex] = temp;
  123.  
  124. tempEx = firstExercise;
  125. firstExercise = secondExercise;
  126. secondExercise = tempEx;
  127. }
  128. else
  129. {
  130. temp = courseSchedule[firstIndex];
  131. courseSchedule[firstIndex] = courseSchedule[secondIndex];
  132. courseSchedule[secondIndex] = temp;
  133.  
  134.  
  135. }
  136. }
  137. }
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement