braveheart1989

Pairs

Apr 11th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 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 _2.Pairs
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14.             List<int> sum = new List<int>();
  15.             int currSum = array[0] + array[1];
  16.             if (array.Length == 2 && array[0]==array[1])
  17.             {
  18.                 Console.WriteLine("Yes, value={0}", currSum);
  19.                 return;
  20.             }
  21.             int nextsum = 0;
  22.             bool areEqual = false;
  23.             bool maxDifference = false;
  24.             int diff = 0;
  25.             int maxDiff = int.MinValue;
  26.             sum.Add(currSum);
  27.             for (int i = 2; i < array.Length; i++)
  28.             {
  29.                 nextsum = array[i] + array[i + 1];
  30.                 sum.Add(nextsum);
  31.  
  32.                 if (currSum == nextsum)
  33.                 {
  34.                     areEqual = true;
  35.                 }
  36.                 i++;
  37.             }
  38.             if (areEqual)
  39.             {
  40.                 Console.WriteLine("Yes, value={0}", nextsum);
  41.                 return;
  42.             }
  43.             for (int i = 0; i < sum.Count-1; i++)
  44.             {
  45.                 diff = Math.Abs(sum[i] - sum[i+1]);
  46.                 if (diff > maxDiff)
  47.                 {
  48.                     maxDiff = diff;
  49.                     maxDifference = true;
  50.                 }
  51.             }
  52.             if (maxDifference)
  53.             {
  54.                 Console.WriteLine("No, maxdiff={0}", maxDiff);
  55.             }
  56.         }
  57.     }
  58. }
Add Comment
Please, Sign In to add comment