Daniel_007

04. Equal Pairs

Oct 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 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 howMany = int.Parse(Console.ReadLine());
  10.             int max = int.MinValue;
  11.             int firstNum = 0;
  12.             int secondNum = 0;
  13.             int sum1 = 0;
  14.             int sum2 = 0;
  15.             int checker = 1;
  16.             if (howMany > 1) {
  17.                 for (int i = 0; i < howMany; i++)
  18.                 {
  19.                     firstNum = int.Parse(Console.ReadLine());
  20.                     secondNum = int.Parse(Console.ReadLine());
  21.                     if (i % 2 == 0)
  22.                     {
  23.                         sum1 = firstNum + secondNum;
  24.                     }
  25.                     else
  26.                     {
  27.                         sum2 = firstNum + secondNum;
  28.                     }
  29.  
  30.                     if (sum1 == sum2)
  31.                     {
  32.                         checker++;
  33.  
  34.                     }
  35.                     if (i >= 1 && sum1 != sum2)
  36.                     {
  37.                         if (max < (Math.Abs(sum2 - sum1)))
  38.                         {
  39.                             max = Math.Abs(sum2 - sum1);
  40.                         }
  41.                     }
  42.                 }
  43.                 if (checker == howMany)
  44.                 {
  45.                     Console.WriteLine($"Yes, value={sum2}");
  46.                 }
  47.                 else
  48.                 {
  49.                     Console.WriteLine($"No, maxdiff={max}");
  50.                 }
  51.             }else
  52.             {
  53.                 firstNum = int.Parse(Console.ReadLine());
  54.                 secondNum = int.Parse(Console.ReadLine());
  55.                 Console.WriteLine($"Yes, value={firstNum + secondNum}");
  56.             }
  57.  
  58.         }
  59.     }
  60. }
Add Comment
Please, Sign In to add comment