Advertisement
GabrielDas

Untitled

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