Pretorianbg

Untitled

Feb 22nd, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace SoftUni_Course_Planning
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. var courses = Console.ReadLine()
  11. .Split(", ")
  12. .ToList();
  13.  
  14. while (true)
  15. {
  16. string command = Console.ReadLine();
  17. if (command == "course start")
  18. {
  19. break;
  20. }
  21.  
  22. var tokens = command.Split(":");
  23.  
  24. if (tokens[0] == "Add" && courses.Contains(tokens[1]) == false)
  25. {
  26. courses.Add(tokens[1]);
  27. }
  28.  
  29. else if (tokens[0] == "Insert" && courses.Contains(tokens[1]) == false)
  30. {
  31. courses.Insert(int.Parse(tokens[2]), tokens[1]);
  32. }
  33.  
  34. else if (tokens[0] == "Remove" && courses.Contains(tokens[1]))
  35. {
  36. string course = tokens[1];
  37. courses.Remove(tokens[1]);
  38. courses.Remove($"{course}-Exercise");
  39. }
  40.  
  41. else if (tokens[0] == "Swap" && courses.Contains(tokens[1]) && courses.Contains(tokens[2]))
  42. {
  43. int indexOfFirst = courses.IndexOf(tokens[1]);
  44. int indexOfSecond = courses.IndexOf(tokens[2]);
  45.  
  46. string firstCourse = courses[indexOfFirst];
  47. string secondCourse = courses[indexOfSecond];
  48.  
  49. courses[indexOfFirst] = secondCourse;
  50. courses[indexOfSecond] = firstCourse;
  51.  
  52. if (courses.Contains($"{firstCourse}-Exercise"))
  53. {
  54. courses.RemoveAt(indexOfFirst + 1);
  55. courses.Insert(indexOfSecond + 1, $"{firstCourse}-Exercise");
  56. }
  57.  
  58. if (courses.Contains($"{secondCourse}-Exercise"))
  59. {
  60.  
  61. courses.RemoveAt(indexOfSecond + 1);
  62. courses.Insert(indexOfFirst + 1, $"{secondCourse}-Exercise");
  63.  
  64. }
  65. }
  66.  
  67. else if (tokens[0] == "Exercise")
  68. {
  69. string lesson = tokens[1];
  70. string lessonExercise = ($"{tokens[1]}-Exercise");
  71.  
  72. if (courses.Contains(lesson) == false)
  73. {
  74. courses.Add(lesson);
  75. courses.Add(lessonExercise);
  76. }
  77. else
  78. {
  79. int indexOfLesson = courses.IndexOf(lesson);
  80. courses.Insert(indexOfLesson + 1, lessonExercise);
  81. }
  82. }
  83. }
  84.  
  85. for (int i = 0; i < courses.Count; i++)
  86. {
  87. Console.WriteLine($"{i + 1}.{courses[i]}");
  88. }
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment