Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Underground_waters
- {
- class Program
- {
- static void Main(string[] args)
- {
- string inputOne = Console.ReadLine();
- string inputTwo = Console.ReadLine();
- int NumberOfLocalMax = 0;
- int MaxMax = 0;
- if (inputOne == "")
- {
- int[] ValidData = new int[2] { 0, 0 };
- }
- else
- {
- int[] AirArray = GetInputArray(inputOne);
- int[] ValidData = ExtractNumberOfLocalMaxFromAirArray(AirArray);
- NumberOfLocalMax = ValidData[0];
- MaxMax = ValidData[1];
- }
- List<int> EdittedRaindropsList = new List<int>();
- if (inputTwo == "")
- {
- EdittedRaindropsList = null;
- }
- else
- {
- int[] RaindropsArray = GetInputArray(inputTwo);
- EditTheRaindropsArray(RaindropsArray, NumberOfLocalMax);
- EdittedRaindropsList = GetValidRaindrops(RaindropsArray);
- }
- int SecondMaxMax = 0;
- if (EdittedRaindropsList != null)
- {
- for (int i = 0; i < EdittedRaindropsList.Count; i++)
- {
- if (EdittedRaindropsList[i] > SecondMaxMax)
- {
- SecondMaxMax = EdittedRaindropsList[i];
- }
- }
- }
- if (MaxMax == SecondMaxMax)
- {
- Console.WriteLine("Something interesting was found!");
- Console.WriteLine($"Sum: {MaxMax + SecondMaxMax}");
- }
- else
- {
- Console.WriteLine("There is nothing unordinary!");
- Console.WriteLine($"Difference: {Math.Abs(MaxMax - SecondMaxMax)}");
- }
- }
- private static List<int> GetValidRaindrops(int[] RaindropsArray)
- {
- List<int> EdittedRaindropsList = new List<int>();
- for (int i = 0; i < RaindropsArray.Length; i++)
- {
- if (RaindropsArray[i] > 0)
- {
- EdittedRaindropsList.Add(RaindropsArray[i]);
- }
- }
- return EdittedRaindropsList;
- }
- private static void EditTheRaindropsArray(int[] RaindropsArray, int NumberOfLocalMax)
- {
- for (int i = 0; i < RaindropsArray.Length; i++)
- {
- RaindropsArray[i] -= NumberOfLocalMax;
- }
- }
- private static int[] ExtractNumberOfLocalMaxFromAirArray(int[] AirArray)
- {
- int NumberOfLocalMax = 0;
- int MaxMax = 0;
- int[] NeededData = new int[2];
- for (int i = 0; i < AirArray.Length; i++)
- {
- if (AirArray.Length == 1)
- {
- NumberOfLocalMax = 1;
- MaxMax = AirArray[0];
- }
- else
- {
- if (i == 0)
- {
- if (0 < AirArray[i] && AirArray[i] > AirArray[i + 1])
- {
- NumberOfLocalMax++;
- MaxMax = AirArray[0];
- }
- }
- else if (i == AirArray.Length - 1)
- {
- if (AirArray[i - 1] < AirArray[i] && AirArray[i] > 0)
- {
- NumberOfLocalMax++;
- if (MaxMax < AirArray[i])
- {
- MaxMax = AirArray[i];
- }
- }
- }
- else
- {
- if (AirArray[i - 1] < AirArray[i] && AirArray[i] > AirArray[i + 1])
- {
- NumberOfLocalMax++;
- if (MaxMax < AirArray[i])
- {
- MaxMax = AirArray[i];
- }
- }
- }
- }
- }
- NeededData[0] = NumberOfLocalMax;
- NeededData[1] = MaxMax;
- return NeededData;
- }
- private static int[] GetInputArray(string input)
- {
- return input.Split(' ').Select(s => int.Parse(s)).ToArray();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement