ambiorixdr

EqualPairs

Nov 17th, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 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.             var n = int.Parse(Console.ReadLine());
  14.  
  15.             int currentSum = 0;
  16.             int previousSum = 0;
  17.             int difference = 0;
  18.             int maxdifference = 0;
  19.  
  20.             for (int i = 1; i <= n; i++)
  21.             {
  22.                 var num1 = int.Parse(Console.ReadLine());
  23.                 var num2 = int.Parse(Console.ReadLine());
  24.                 currentSum = num1 + num2;
  25.  
  26.                 if (i > 1) // za vsqka dvoika bez pyrvata presmqtaite razlikata s predhodnata:
  27.                 {
  28.                     difference = Math.Abs(previousSum - currentSum);
  29.                     if (difference > maxdifference)
  30.                     {
  31.                         maxdifference = difference; // namirame nai-golqmata razlika
  32.                     }
  33.                 }
  34.                 previousSum = currentSum;
  35.             }
  36.  
  37.             if (maxdifference == 0) // ako razlikata e 0 znachi vsichki sumi sa ednakvi
  38.             {
  39.                 Console.WriteLine("Yes, value={0}", previousSum);
  40.             }
  41.  
  42.             else
  43.             {
  44.                 Console.WriteLine("No, maxdiff={0}", maxdifference);
  45.             }
  46.  
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment