morgan73

Equal Pairs /C# Programming Basic/

Oct 2nd, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 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 _12.Equal_Pairs
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             int oldSum = 0;
  16.             int currentSum = 0;
  17.             int maxDiff = 0;
  18.             int currentDiff = 0;
  19.  
  20.             for (int i = 0; i < n; i++)
  21.             {
  22.                 int n1 = int.Parse(Console.ReadLine());
  23.                 int n2 = int.Parse(Console.ReadLine());
  24.  
  25.                 currentSum = n1 + n2;
  26.  
  27.                 if (i > 0)
  28.                 {
  29.                     currentDiff = Math.Abs(oldSum - currentSum);
  30.                     if (currentDiff > maxDiff)
  31.                     {
  32.                         maxDiff = currentDiff;
  33.                     }
  34.                 }
  35.  
  36.                 oldSum = currentSum; //Това е важно да е в края на цикъла
  37.                
  38.             }
  39.                
  40.             if (currentDiff == 0) //Тук се замотах - вместо да правя проверка за разликата, аз правих проверки на сумите
  41.             {
  42.                 Console.WriteLine("Yes, value={0}", oldSum);
  43.             }
  44.  
  45.             else
  46.             {
  47.                 Console.WriteLine("No, maxdiff={0}", maxDiff);
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment