Advertisement
Guest User

Untitled

a guest
Apr 14th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _02.Pairs
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             string[] input = Console.ReadLine().Split(' ');
  10.             int maxDiff = 0;
  11.             int oldPair = 0;
  12.             int valueOne = 0;
  13.             int valueTwo = 0;
  14.             int currentPair = 0;
  15.             for (int i = 0, k = 0; i < input.Length / 2; i++, k += 2)
  16.             {
  17.                 valueOne = int.Parse(input[k]);
  18.                 valueTwo = int.Parse(input[k + 1]);
  19.                 oldPair = currentPair;
  20.                 currentPair = valueOne + valueTwo;
  21.                 if (i != 0 && currentPair != oldPair)
  22.                 {
  23.                     int diff = Math.Abs(currentPair - oldPair);
  24.                     if (diff > maxDiff)
  25.                     {
  26.                         maxDiff = diff;
  27.                     }
  28.                 }
  29.                 else
  30.                 {
  31.                     oldPair = currentPair;
  32.                 }
  33.             }
  34.             if (maxDiff != 0)
  35.             {
  36.                 Console.WriteLine("No, maxdiff=" + maxDiff);
  37.             }
  38.             else
  39.             {
  40.                 Console.WriteLine("Yes, value=" + (valueOne + valueTwo));
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement