Advertisement
simonradev

EqualPairs

Jul 29th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 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 LiveDemo
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             int firstPair = 0;
  16.             int secondPair = 0;
  17.             int maxDiff = 0;
  18.             for (int i = 0; i < n; i++)
  19.             {
  20.                 secondPair = firstPair;
  21.  
  22.                 int firstNumber = int.Parse(Console.ReadLine());
  23.                 int secondNumber = int.Parse(Console.ReadLine());
  24.  
  25.                 firstPair = firstNumber + secondNumber;
  26.  
  27.                 if (i > 0)
  28.                 {
  29.                     int currentDiff = Math.Abs(secondPair - firstPair);
  30.  
  31.                     if (currentDiff > maxDiff)
  32.                     {
  33.                         maxDiff = currentDiff;
  34.                     }
  35.                 }
  36.             }
  37.  
  38.             if (maxDiff == 0)
  39.             {
  40.                 // No diff
  41.                 Console.WriteLine($"Yes, value={firstPair}");
  42.             }
  43.             else
  44.             {
  45.                 Console.WriteLine($"No, maxdiff={maxDiff}");
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement