Advertisement
simonradev

EqualPairs

Feb 25th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 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 EqualPairs
  8. {
  9.     class EqualPairs
  10.     {
  11.         static void Main()
  12.         {
  13.             int numberOfPairs = int.Parse(Console.ReadLine());
  14.  
  15.             int currSum = 0;
  16.             int prevSum = 0;
  17.             bool sumsAreDifferent = false;
  18.             int maxDiff = int.MinValue;
  19.             for (int currPair = 0; currPair < numberOfPairs; currPair++)
  20.             {
  21.                 prevSum = currSum;
  22.  
  23.                 int firstNum = int.Parse(Console.ReadLine());
  24.                 int secondNum = int.Parse(Console.ReadLine());
  25.  
  26.                 currSum = firstNum + secondNum;
  27.  
  28.                 int currDiff = 0;
  29.                 if (currPair >= 1 && currSum != prevSum)
  30.                 {
  31.                     sumsAreDifferent = true;
  32.  
  33.                     currDiff = Math.Abs(currSum - prevSum);
  34.                 }
  35.                
  36.                 if (sumsAreDifferent && currDiff > maxDiff)
  37.                 {
  38.                     maxDiff = currDiff;
  39.                 }
  40.             }
  41.  
  42.             if (!sumsAreDifferent)
  43.             {
  44.                 Console.WriteLine($"Yes, value={currSum}");
  45.             }
  46.             else
  47.             {
  48.                 Console.WriteLine($"No, maxdiff={maxDiff}");
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement