Advertisement
iordan_93

Pairs

Apr 14th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Pairs
  6. {
  7.     static void Main()
  8.     {
  9.         string[] elementsSplit = Console.ReadLine().Split(' ');
  10.         List<int> elements = new List<int>();
  11.  
  12.         foreach (string element in elementsSplit)
  13.         {
  14.             elements.Add(int.Parse(element));
  15.         }
  16.  
  17.         List<int> values = new List<int>();
  18.         List<int> differences = new List<int>() { 0 };
  19.         int? sum = null;
  20.         for (int i = 0; i < elements.Count; i += 2)
  21.         {
  22.             int currentSum = elements[i] + elements[i + 1];
  23.             if (!sum.HasValue)
  24.             {
  25.                 sum = currentSum;
  26.             }
  27.  
  28.             values.Add(currentSum);
  29.         }
  30.  
  31.         for (int i = 0; i < values.Count - 1; i++)
  32.         {
  33.             differences.Add(Math.Abs(values[i + 1] - values[i]));
  34.         }
  35.  
  36.         int max = differences.Max();
  37.         if (max == 0)
  38.         {
  39.             Console.WriteLine("Yes, value={0}", sum);
  40.         }
  41.         else
  42.         {
  43.             Console.WriteLine("No, maxdiff={0}", max);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement