Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SoftUniCoursePlanning
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. List<string> schedule = Console.ReadLine()
  12. .Split(", ", StringSplitOptions.RemoveEmptyEntries)
  13. .ToList();
  14.  
  15.  
  16. string imput = Console.ReadLine();
  17.  
  18. while (imput != "course start")
  19. {
  20. string[] command = imput
  21. .Split(':')
  22. .ToArray();
  23.  
  24. if (command[0] == "Add")
  25. {
  26. if(!schedule.Contains(command[1]))
  27. {
  28. schedule.Add(command[1]);
  29. }
  30. }
  31. else if (command[0] == "Insert")
  32. {
  33. if (!schedule.Contains(command[1]))
  34. {
  35. if(int.Parse(command[2]) >= 0 && int.Parse(command[2]) < schedule.Count)
  36. {
  37. schedule.Insert(int.Parse(command[2]), command[1]);
  38. }
  39.  
  40. }
  41. }
  42. else if (command[0] == "Remove")
  43. {
  44. if (schedule.Contains(command[1]))
  45. {
  46. schedule.Remove(command[1]);
  47. }
  48.  
  49. string exercise = command[1] + "-Exercise";
  50.  
  51. if (schedule.Contains(exercise))
  52. {
  53. schedule.Remove(exercise);
  54. }
  55. }
  56. else if (command[0] == "Exercise")
  57. {
  58. if (schedule.Contains(command[1]))
  59. {
  60. int indexOfLesson = schedule.IndexOf(command[1]);
  61. int indexOfExercise = indexOfLesson + 1;
  62. string addition = command[1] + "-Exercise";
  63. schedule.Insert(indexOfExercise, addition);
  64. }
  65. else
  66. {
  67. string addition = command[1] + "-Exercise";
  68. schedule.Add(command[1]);
  69. schedule.Add(addition);
  70. }
  71. }
  72. else if (command[0] == "Swap")
  73. {
  74. if (schedule.Contains(command[1]) && schedule.Contains(command[2]))
  75. {
  76. string firstExercise = command[1] + "-Exercise";
  77. string secondExercise = command[2] + "-Exercise";
  78.  
  79. int indexOfFirst = schedule.IndexOf(command[1]);
  80.  
  81. string firstText = command[1];
  82.  
  83. int indexOfSecond = schedule.IndexOf(command[2]);
  84.  
  85. string secondtext = command[2];
  86.  
  87. int originalIndexOfFirst = indexOfFirst;
  88. int originalIndexOfSecond = indexOfSecond;
  89.  
  90. if(indexOfFirst > indexOfSecond)
  91. {
  92. indexOfFirst = originalIndexOfSecond;
  93. firstExercise = command[2] + "-Exercise";
  94. firstText = command[2];
  95. secondtext = command[1];
  96. indexOfSecond = originalIndexOfFirst;
  97. secondExercise = command[1] + "-Exercise";
  98. }
  99.  
  100. if (!schedule.Contains(firstExercise) && !schedule.Contains(secondExercise))
  101. {
  102. schedule.RemoveAt(indexOfFirst);
  103. schedule.Insert(indexOfFirst, secondtext);
  104. schedule.RemoveAt(indexOfSecond);
  105. schedule.Insert(indexOfSecond, firstText);
  106. }
  107. else if (schedule.Contains(firstExercise) && !schedule.Contains(secondExercise))
  108. {
  109. schedule.RemoveAt(indexOfFirst);
  110. schedule.RemoveAt(indexOfFirst);
  111. schedule.Remove(secondtext);
  112. schedule.Insert(indexOfFirst, secondtext);
  113. if (indexOfSecond >= schedule.Count)
  114. {
  115. schedule.Add(firstText);
  116. schedule.Add(firstText + "-Exercise");
  117. }
  118. else
  119. {
  120. schedule.Insert(indexOfSecond, firstText + "-Exercise");
  121. schedule.Insert(indexOfSecond, firstText);
  122. }
  123. }
  124. else if (!schedule.Contains(firstExercise) && schedule.Contains(secondExercise))
  125. {
  126. schedule.RemoveAt(indexOfFirst);
  127. schedule.Insert(indexOfFirst, secondtext);
  128. schedule.Insert(indexOfFirst + 1, secondtext + "-Exercise");
  129. schedule.RemoveAt(indexOfSecond + 1);
  130. schedule.RemoveAt(indexOfSecond + 1);
  131. schedule.Insert(indexOfSecond +1, firstText);
  132. }
  133. else if (schedule.Contains(firstExercise) && schedule.Contains(secondExercise))
  134. {
  135. schedule.RemoveAt(indexOfFirst);
  136. schedule.RemoveAt(indexOfFirst);
  137. schedule.Insert(indexOfFirst, secondtext + "-Exercise");
  138. schedule.Insert(indexOfFirst, secondtext);
  139. schedule.RemoveAt(indexOfSecond);
  140. schedule.RemoveAt(indexOfSecond);
  141. schedule.Insert(indexOfSecond, firstText + "-Exercise");
  142. schedule.Insert(indexOfSecond, firstText);
  143. }
  144. }
  145. }
  146.  
  147. imput = Console.ReadLine();
  148. }
  149.  
  150. for (int i = 1; i <= schedule.Count; i++)
  151. {
  152. Console.WriteLine($"{i}.{schedule[i-1]}");
  153. }
  154. }
  155. }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement