Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main()
- {
- //take input from console
- string first = Console.ReadLine();
- string[] splitted = first.Split(' ');//split them with empty spaces
- int[] Arr = new int[splitted.Length];//int array for string console values
- for (int i = 0; i < splitted.Length; i++)//goes true all elements and converts them into Int32
- {
- Arr[i] = int.Parse(splitted[i]);
- }
- //for (int i = 0; i < Arr.Length; i++)//print array to see what happened
- //{
- // Console.WriteLine(Arr[i]);
- //}
- int[] novArr = new int[(Arr.Length / 2)];
- int sum = 0;
- for (int i = 0; i < Arr.Length; i += 2)
- {
- if (i + 1 < Arr.Length)
- {
- novArr[sum] = Arr[i] + Arr[i + 1];
- }
- else
- {
- novArr[sum] = Arr[i];
- }
- sum++;
- }
- //check if the values are equal
- int counter = 0;
- int value = 0;
- for (int i = 0; i < novArr.Length - 1; i++)
- {
- if (novArr[i] == novArr[i + 1])
- {
- counter++;
- }
- else
- {
- //#1 EDIT: looking for the MAX difference,
- //Math.Abs should be here as well
- //example: Math.Max(90,-150) = 90...
- value = Math.Max(value, Math.Abs(novArr[i] - novArr[i + 1]));
- }
- }
- //#2 EDIT: formatting edit + no Math.Abs here
- if (counter == novArr.Length - 1)
- {
- Console.WriteLine("Yes, value={0}", novArr[0]);
- }
- else
- {
- Console.WriteLine("No, maxdiff={0}", value);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement