Advertisement
VanessaShopping

Homework 18 Equal Pairs

Feb 16th, 2016
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2.  
  3. class EqualPairs
  4. {
  5.     static void Main()
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.         int a = int.Parse(Console.ReadLine());
  9.         int b = int.Parse(Console.ReadLine());
  10.         int currentSum = 0;
  11.         int previousSum = a + b;
  12.         int maxDiff = int.MinValue;
  13.         int currentDiff = 0;
  14.  
  15.  
  16.         for (int i = 1; i <= n - 1; i++)
  17.         {
  18.             a = int.Parse(Console.ReadLine());
  19.             b = int.Parse(Console.ReadLine());
  20.             currentSum = a + b;
  21.             currentDiff = Math.Abs(currentSum - previousSum);
  22.             if (currentDiff > maxDiff)
  23.             {
  24.                 maxDiff = currentDiff;
  25.             }
  26.         }
  27.         if (maxDiff == 0)
  28.         {
  29.             Console.WriteLine("Yes value " + currentSum);
  30.         }
  31.         else
  32.         {
  33.             Console.WriteLine("no maxdiff " + maxDiff);
  34.         }
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement