Guest User

Untitled

a guest
Oct 23rd, 2019
90
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _10_SoftUniCoursePlanning
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> lessonSchedule = Console.ReadLine()
  12. .Split(", ")
  13. .ToList();
  14. string comand = Console.ReadLine();
  15.  
  16. while (comand != "course start")
  17. {
  18. string[] comandArray = comand.Split(":");
  19. string comandName = comandArray[0];
  20. string lessonTitle = comandArray[1];
  21.  
  22. switch (comandName)
  23. {
  24. case "Add":
  25. if (!lessonSchedule.Contains(lessonTitle))
  26. {
  27. lessonSchedule.Add(lessonTitle);
  28. }
  29. break;
  30. case "Insert":
  31. if (!lessonSchedule.Contains(lessonTitle))
  32. {
  33. int position = int.Parse(comandArray[2]);
  34. lessonSchedule.Insert(position,lessonTitle);
  35. }
  36. break;
  37. case "Remove":
  38. if (lessonSchedule.Contains(lessonTitle))
  39. {
  40. lessonSchedule.Remove(lessonTitle);
  41. }
  42. break;
  43. case "Swap":
  44. string secondLesonTitle = comandArray[2];
  45. SwapPositionOfLessons(lessonSchedule, lessonTitle, secondLesonTitle);
  46. break;
  47. case "Exercise":
  48. if (!lessonSchedule.Contains(lessonTitle))
  49. {
  50. string lessonExercise = lessonTitle + "-Exercise";
  51. lessonSchedule.Add(lessonTitle);
  52. lessonSchedule.Add(lessonExercise);
  53. }
  54. else
  55. {
  56. AddExercise(lessonSchedule, lessonTitle);
  57. }
  58. break;
  59. }
  60.  
  61.  
  62. comand = Console.ReadLine();
  63. }
  64.  
  65. for (int j = 0; j < lessonSchedule.Count; j++)
  66. {
  67. Console.WriteLine($"{j+1}.{lessonSchedule[j]}");
  68. }
  69.  
  70. }
  71.  
  72. static void SwapPositionOfLessons(List<string> lessonsSchedule,string firstName, string secondName)
  73. {
  74. if (lessonsSchedule.Contains(firstName) && lessonsSchedule.Contains(secondName))
  75. {
  76. int firstPosition = 0;
  77. int secondPosition = 0;
  78. string firstNameExercise = firstName + "-Exercise";
  79. string secondNameExercise = secondName + "-Exercise";
  80.  
  81. for (int i = 0; i < lessonsSchedule.Count; i++)
  82. {
  83. if (lessonsSchedule[i] == firstName)
  84. {
  85. lessonsSchedule[i] = secondName;
  86. firstPosition = i;
  87. }
  88. else if (lessonsSchedule[i] == secondName)
  89. {
  90. lessonsSchedule[i] = firstName;
  91. secondPosition = i;
  92. }
  93. }
  94. if (lessonsSchedule.Contains(firstNameExercise))
  95. {
  96. lessonsSchedule.Remove(firstNameExercise);
  97. lessonsSchedule.Insert(secondPosition + 1, firstNameExercise);
  98. }
  99. if (lessonsSchedule.Contains(secondNameExercise))
  100. {
  101. lessonsSchedule.Remove(secondNameExercise);
  102. lessonsSchedule.Insert(firstPosition + 1, secondNameExercise);
  103. }
  104.  
  105. }
  106. }
  107. static void AddExercise(List<string> lesonSchedule, string exerciseName)
  108. {
  109. for (int i = 0; i < lesonSchedule.Count; i++)
  110. {
  111. if (lesonSchedule[i] == exerciseName)
  112. {
  113. string lessonExercise = exerciseName + "-Exercise";
  114.  
  115. lesonSchedule.Insert(i + 1, lessonExercise);
  116. break;
  117. }
  118. }
  119. }
  120.  
  121. }
  122. }
RAW Paste Data