Teo_Yanchev

03. LastStop - C# Fundamentals EXAM G1 - 10.03.2019

Sep 27th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _10._03._2019_Mid_Exam
  6. {
  7. class LastStop
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> numbers = Console.ReadLine()
  12. .Split()
  13. .Select(int.Parse)
  14. .ToList();
  15.  
  16. string command = Console.ReadLine();
  17. while (command != "END")
  18. {
  19. string[] instructions = command.Split();
  20. string currentInstruction = instructions[0];
  21.  
  22. if (currentInstruction == "Reverse")
  23. {
  24. numbers.Reverse();
  25. }
  26.  
  27. else if (instructions.Length - 1 > 0)
  28. {
  29.  
  30. int paintingNumber = int.Parse(instructions[1]);
  31.  
  32. if (currentInstruction == "Change")
  33. {
  34. if (numbers.Contains(paintingNumber))
  35. {
  36. int changeNumber = int.Parse(instructions[2]);
  37. int currentIndex = numbers.IndexOf(paintingNumber);
  38.  
  39. numbers.Remove(paintingNumber);
  40. numbers.Insert(currentIndex, changeNumber);
  41.  
  42. }
  43. else
  44. {
  45. command = Console.ReadLine();
  46. continue;
  47. }
  48. }
  49.  
  50. else if (currentInstruction == "Hide")
  51. {
  52. if (numbers.Contains(paintingNumber))
  53. {
  54. numbers.Remove(paintingNumber);
  55. }
  56. else
  57. {
  58. command = Console.ReadLine();
  59. continue;
  60. }
  61. }
  62.  
  63. else if (currentInstruction == "Switch")
  64. {
  65. int secondPaintingNumber = int.Parse(instructions[2]);
  66. bool isContains = numbers.Contains(paintingNumber) && numbers.Contains(secondPaintingNumber);
  67.  
  68. if (isContains)
  69. {
  70. int currentPaintIndex = numbers.IndexOf(paintingNumber);
  71. int changePaintIndex = numbers.IndexOf(secondPaintingNumber);
  72.  
  73. numbers.RemoveAt(currentPaintIndex);
  74. numbers.Insert(currentPaintIndex, secondPaintingNumber);
  75. numbers.RemoveAt(changePaintIndex);
  76. numbers.Insert(changePaintIndex, paintingNumber);
  77. }
  78. else
  79. {
  80. command = Console.ReadLine();
  81. continue;
  82. }
  83. }
  84.  
  85. else if (currentInstruction == "Insert")
  86. {
  87. int index = paintingNumber + 1;
  88. paintingNumber = int.Parse(instructions[2]);
  89. bool isInside = 0 <= index && index <= numbers.Count - 1;
  90. if (isInside)
  91. {
  92. numbers.Insert(index, paintingNumber);
  93. }
  94. else
  95. {
  96. command = Console.ReadLine();
  97. continue;
  98. }
  99. }
  100. }
  101.  
  102.  
  103. command = Console.ReadLine();
  104. }
  105.  
  106. Console.WriteLine(string.Join(' ', numbers));
  107. }
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment