Advertisement
viraco4a

1_Underground_Waters

Jan 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 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 Underground_waters
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string inputOne = Console.ReadLine();
  14. string inputTwo = Console.ReadLine();
  15. int NumberOfLocalMax = 0;
  16. int MaxMax = 0;
  17. if (inputOne == "")
  18. {
  19. int[] ValidData = new int[2] { 0, 0 };
  20. }
  21. else
  22. {
  23. int[] AirArray = GetInputArray(inputOne);
  24. int[] ValidData = ExtractNumberOfLocalMaxFromAirArray(AirArray);
  25. NumberOfLocalMax = ValidData[0];
  26. MaxMax = ValidData[1];
  27. }
  28.  
  29. List<int> EdittedRaindropsList = new List<int>();
  30. if (inputTwo == "")
  31. {
  32. EdittedRaindropsList = null;
  33. }
  34. else
  35. {
  36. int[] RaindropsArray = GetInputArray(inputTwo);
  37. EditTheRaindropsArray(RaindropsArray, NumberOfLocalMax);
  38. EdittedRaindropsList = GetValidRaindrops(RaindropsArray);
  39. }
  40.  
  41. int SecondMaxMax = 0;
  42. if (EdittedRaindropsList != null)
  43. {
  44. for (int i = 0; i < EdittedRaindropsList.Count; i++)
  45. {
  46. if (EdittedRaindropsList[i] > SecondMaxMax)
  47. {
  48. SecondMaxMax = EdittedRaindropsList[i];
  49. }
  50. }
  51. }
  52.  
  53. if (MaxMax == SecondMaxMax)
  54. {
  55. Console.WriteLine("Something interesting was found!");
  56. Console.WriteLine($"Sum: {MaxMax + SecondMaxMax}");
  57. }
  58. else
  59. {
  60. Console.WriteLine("There is nothing unordinary!");
  61. Console.WriteLine($"Difference: {Math.Abs(MaxMax - SecondMaxMax)}");
  62. }
  63.  
  64.  
  65. }
  66.  
  67. private static List<int> GetValidRaindrops(int[] RaindropsArray)
  68. {
  69. List<int> EdittedRaindropsList = new List<int>();
  70.  
  71. for (int i = 0; i < RaindropsArray.Length; i++)
  72. {
  73. if (RaindropsArray[i] > 0)
  74. {
  75. EdittedRaindropsList.Add(RaindropsArray[i]);
  76. }
  77. }
  78.  
  79. return EdittedRaindropsList;
  80. }
  81.  
  82. private static void EditTheRaindropsArray(int[] RaindropsArray, int NumberOfLocalMax)
  83. {
  84. for (int i = 0; i < RaindropsArray.Length; i++)
  85. {
  86. RaindropsArray[i] -= NumberOfLocalMax;
  87. }
  88. }
  89.  
  90. private static int[] ExtractNumberOfLocalMaxFromAirArray(int[] AirArray)
  91. {
  92. int NumberOfLocalMax = 0;
  93. int MaxMax = 0;
  94. int[] NeededData = new int[2];
  95.  
  96. for (int i = 0; i < AirArray.Length; i++)
  97. {
  98. if (AirArray.Length == 1)
  99. {
  100. NumberOfLocalMax = 1;
  101. MaxMax = AirArray[0];
  102. }
  103. else
  104. {
  105. if (i == 0)
  106. {
  107. if (0 < AirArray[i] && AirArray[i] > AirArray[i + 1])
  108. {
  109. NumberOfLocalMax++;
  110. MaxMax = AirArray[0];
  111. }
  112. }
  113. else if (i == AirArray.Length - 1)
  114. {
  115. if (AirArray[i - 1] < AirArray[i] && AirArray[i] > 0)
  116. {
  117. NumberOfLocalMax++;
  118. if (MaxMax < AirArray[i])
  119. {
  120. MaxMax = AirArray[i];
  121. }
  122. }
  123. }
  124. else
  125. {
  126. if (AirArray[i - 1] < AirArray[i] && AirArray[i] > AirArray[i + 1])
  127. {
  128. NumberOfLocalMax++;
  129. if (MaxMax < AirArray[i])
  130. {
  131. MaxMax = AirArray[i];
  132. }
  133. }
  134. }
  135. }
  136. }
  137.  
  138. NeededData[0] = NumberOfLocalMax;
  139. NeededData[1] = MaxMax;
  140.  
  141. return NeededData;
  142. }
  143.  
  144. private static int[] GetInputArray(string input)
  145. {
  146. return input.Split(' ').Select(s => int.Parse(s)).ToArray();
  147. }
  148. }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement