Teo_Yanchev

ListsExercise - 5.BombNumbers - C# Fundamentals

Sep 19th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _5.BombNumbers
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. List<int> numbers = Console.ReadLine()
  12. .Split(" ")
  13. .Select(int.Parse)
  14. .ToList();
  15.  
  16. List<int> bombNumber = Console.ReadLine()
  17. .Split(" ")
  18. .Select(int.Parse)
  19. .ToList();
  20.  
  21. int bomb = bombNumber[0];
  22. int bombPower = bombNumber[1];
  23. int currentIndexBomb = numbers.IndexOf(bomb);
  24. int count = 0;
  25. bool left = true;
  26. bool right = true;
  27.  
  28. while (numbers.Contains(bomb))
  29. {
  30.  
  31. if (left)
  32. {
  33. while (count < bombPower)
  34. {
  35. count += 1;
  36. currentIndexBomb = numbers.IndexOf(bomb);
  37. if (currentIndexBomb == 0)
  38. {
  39. left = false;
  40. break;
  41. }
  42.  
  43. else
  44. {
  45. for (int i = currentIndexBomb; i > 0; i--)
  46. {
  47. int index = currentIndexBomb - 1;
  48. numbers.RemoveAt(index);
  49. break;
  50. }
  51. left = false;
  52. }
  53. }
  54.  
  55. count = 0;
  56.  
  57. }
  58.  
  59. if (right)
  60. {
  61. while (count < bombPower)
  62. {
  63. count += 1;
  64. currentIndexBomb = numbers.IndexOf(bomb);
  65. if (currentIndexBomb == numbers.Count - 1)
  66. {
  67. right = false;
  68. break;
  69. }
  70.  
  71. else
  72. {
  73. int range = numbers.IndexOf(bomb) + bombPower;
  74. for (int i = currentIndexBomb; i <= range; i++)
  75. {
  76. int index = currentIndexBomb + 1;
  77. numbers.RemoveAt(index);
  78. break;
  79. }
  80. right = false;
  81. }
  82. }
  83. numbers.Remove(bomb);
  84. count = 0;
  85.  
  86. if (numbers.Contains(bomb))
  87. {
  88. left = true;
  89. right = true;
  90. }
  91. }
  92. }
  93. Console.WriteLine(numbers.Sum());
  94. }
  95. }
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment