IordanRujinov

EqualPairs

Mar 4th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 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 Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int N = int.Parse(Console.ReadLine());
  14.             int currentSum = 0;
  15.             int previousSum = 0;
  16.             int diff = 0;
  17.             int maxDiff = 0;
  18.  
  19.             for (int i = 0; i < N; i++)
  20.             {
  21.                 previousSum = currentSum;
  22.                 currentSum = 0;
  23.                 for (int j = 1; j <= 2;j++)
  24.                 {
  25.                     currentSum += int.Parse(Console.ReadLine());
  26.                 }
  27.  
  28.                 if (i != 0) // този if няма да се изпълни при първото завъртане на for i
  29.                 {
  30.                     diff = Math.Abs(currentSum - previousSum);
  31.                     if (diff != 0 && diff > maxDiff)
  32.                     {
  33.                         maxDiff = diff;
  34.                     }
  35.                 }
  36.             }
  37.             if (maxDiff == 0 || N == 1)
  38.             {
  39.                 Console.WriteLine("Yes, value= {0}", currentSum);
  40.             }
  41.             else
  42.             {
  43.                 Console.WriteLine("No, maxDiff= {0}", maxDiff);
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment