Advertisement
Taniaaleksandrova

Untitled

Jun 16th, 2020
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _10._SoftUni_Course_Planning
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> lecture = Console.ReadLine().Split(", ", StringSplitOptions.RemoveEmptyEntries).ToList();
  12. string input = Console.ReadLine();
  13. while (input != "course start")
  14. {
  15. string[] command = input.Split(':').ToArray();
  16.  
  17. if(command[0] == "Add")
  18. {
  19. bool here = false;
  20.  
  21. foreach (var item in lecture)
  22. {
  23. if(item == command[1])
  24. {
  25. here = true;
  26. }
  27. }
  28.  
  29. if(!here)
  30. {
  31. lecture.Add(command[1]);
  32. }
  33. }
  34. else if (command[0] == "Insert")
  35. {
  36. bool here = false;
  37.  
  38. foreach (var item in lecture)
  39. {
  40. if (item == command[1])
  41. {
  42. here = true;
  43. }
  44. }
  45.  
  46. if (!here)
  47. {
  48. lecture.Insert(int.Parse(command[2]),command[1]);
  49. }
  50. }
  51. else if (command[0] == "Remove")
  52. {
  53. bool here = false;
  54. string lectureExercise = string.Empty;
  55. for (int i = 0; i < lecture.Count; i++)
  56. {
  57. lectureExercise = string.Empty;
  58. for (int j = 0; j < lecture[i].Length; j++)
  59. {
  60. if (lecture[i][j] == '-')
  61. {
  62. break;
  63. }
  64. lectureExercise += lecture[i][j];
  65. }
  66. if (lecture[i] == command[1])
  67. {
  68. lecture.Remove(command[1]);
  69. here = true;
  70. break;
  71. }
  72. }
  73. for (int i = 0; i < lecture.Count; i++)
  74. {
  75. if (lecture[i] == $"{lectureExercise}-Exercise" && here == true)
  76. {
  77. lecture.Remove(lecture[i]);
  78. }
  79. }
  80. }
  81. else if (command[0] == "Swap")
  82. {
  83. bool hereLecture1 = false;
  84. bool hereLecture2 = false;
  85. int indexLecture1 = 0;
  86. int indexLecture2 = 0;
  87. string lectureExercise = string.Empty;
  88.  
  89. for (int i = 0; i < lecture.Count; i++)
  90. {
  91. if (lecture[i] == command[1])
  92. {
  93. hereLecture1 = true;
  94. indexLecture1 = i;
  95. }
  96. if (lecture[i] == command[2])
  97. {
  98. hereLecture2 = true;
  99. indexLecture2 = i;
  100. }
  101. }
  102.  
  103. if(hereLecture1 && hereLecture2)
  104. {
  105. string temp = lecture[indexLecture1];
  106. lecture[indexLecture1] = lecture[indexLecture2];
  107. lecture[indexLecture2] = temp;
  108. }
  109.  
  110. lectureExercise = string.Empty;
  111. bool hereExercise = false;
  112. int indexExercise = 0;
  113.  
  114. for (int j = 0; j < lecture[indexLecture1].Length; j++)
  115. {
  116. if (lecture[indexLecture1][j] == '-')
  117. {
  118. break;
  119. }
  120. lectureExercise += lecture[indexLecture1][j];
  121. }
  122. for (int i = 0; i < lecture.Count; i++)
  123. {
  124. if(lecture[i] == $"{lectureExercise}-Exercise")
  125. {
  126. hereExercise = true;
  127. indexExercise = i;
  128. }
  129. }
  130. if(hereExercise)
  131. {
  132. lecture.Insert(indexLecture1 + 1, $"{lectureExercise}-Exercise");
  133. lecture.RemoveAt(indexExercise+1);
  134. }
  135.  
  136. lectureExercise = string.Empty;
  137. hereExercise = false;
  138. indexExercise = 0;
  139.  
  140. for (int j = 0; j < lecture[indexLecture2].Length; j++)
  141. {
  142. if (lecture[indexLecture2][j] == '-')
  143. {
  144. break;
  145. }
  146. lectureExercise += lecture[indexLecture2][j];
  147. }
  148. for (int i = 0; i < lecture.Count; i++)
  149. {
  150. if (lecture[i] == $"{lectureExercise}-Exercise")
  151. {
  152. hereExercise = true;
  153. indexExercise = i;
  154. }
  155. }
  156. if (hereExercise)
  157. {
  158. lecture.Insert(indexLecture2 + 1, $"{lectureExercise}-Exercise");
  159. lecture.RemoveAt(indexExercise+1);
  160. }
  161.  
  162.  
  163. }
  164. else if (command[0] == "Exercise")
  165. {
  166. bool hereLecture = false;
  167. bool hereExercise = false;
  168. int indexLecture = 0;
  169. int indexExercise = 0;
  170. string lectureExercise = string.Empty;
  171.  
  172. for (int i = 0; i < lecture.Count;i++)
  173. {
  174. lectureExercise = string.Empty;
  175. for (int j = 0; j < lecture[i].Length; j++)
  176. {
  177. if(lecture[i][j] == '-')
  178. {
  179. break;
  180. }
  181. lectureExercise += lecture[i][j];
  182. }
  183. if (lecture[i] == command[1])
  184. {
  185. hereLecture = true;
  186. indexLecture = i;
  187. }
  188. if (lecture[i] == $"{lectureExercise}-Exercise")
  189. {
  190. hereExercise = true;
  191. indexExercise = i;
  192. }
  193. }
  194.  
  195. string exercise = command[1] + "-Exercise";
  196.  
  197. if (!hereLecture && !hereExercise)
  198. {
  199. lecture.Add(command[1]);
  200. lecture.Add(exercise);
  201. }
  202. else if(hereLecture && !hereExercise)
  203. {
  204. lecture.Insert(indexLecture+1, exercise);
  205. }
  206. else if(!hereLecture && hereExercise)
  207. {
  208. lecture.Insert(indexExercise, command[1]);
  209. }
  210. }
  211. input = Console.ReadLine();
  212. }
  213. for (int i = 0; i < lecture.Count; i++)
  214. {
  215. Console.WriteLine($"{i+1}.{lecture[i]}");
  216. }
  217. }
  218. }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement