Advertisement
anizko

04. Equal Pairs

Apr 10th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Equal_Pairs
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int countNum = int.Parse(Console.ReadLine());
  10.          
  11.             double beforePearSum = 0;
  12.             double maxDiff = 0;
  13.             double pear = 0;
  14.             int i = 0;
  15.             double num1 = 0;
  16.             double num2 = 0;
  17.  
  18.  
  19.             for (; i < countNum; i++)
  20.             {
  21.                 if (i == 0)
  22.                 {
  23.                     num1 = double.Parse(Console.ReadLine());
  24.                     num2 = double.Parse(Console.ReadLine());
  25.  
  26.                     beforePearSum = num1 + num2;
  27.                 }
  28.                 else
  29.                 {
  30.                     num1 = double.Parse(Console.ReadLine());
  31.                     num2 = double.Parse(Console.ReadLine());
  32.  
  33.                     pear = num1 + num2;
  34.  
  35.                     double Diff = Math.Abs(pear - beforePearSum);
  36.                     if (Diff > maxDiff)
  37.                     {
  38.                         maxDiff = Diff;
  39.                     }
  40.                     beforePearSum = pear;
  41.                 }
  42.             }
  43.  
  44.            
  45.             if (i == 1 && num1 == num2)
  46.             {
  47.                 Console.WriteLine($"Yes, value={beforePearSum}");
  48.             }
  49.             else if (maxDiff == 0)
  50.             {
  51.                 Console.WriteLine($"Yes, value={pear}");
  52.             }
  53.             else
  54.             {
  55.             Console.WriteLine($"No, maxdiff={maxDiff}");
  56.             }
  57.  
  58.  
  59.            
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement