joro_thexfiles

4.Еднакви двойки

Apr 8th, 2019
585
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 _4.Еднакви_двойки
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             double sumEven = 0;
  15.             double sumOdd = 0;
  16.             double diff = -3333333;
  17.             double max = int.MinValue;
  18.  
  19.             for (int i = 1; i <= n; i++)
  20.             {
  21.                 double num1 = double.Parse(Console.ReadLine());
  22.                 double num2 = double.Parse(Console.ReadLine());
  23.  
  24.                 if (i % 2 == 0)
  25.                 {
  26.                     sumEven = num1 + num2;
  27.                 }
  28.                 else
  29.                 {
  30.                     sumOdd = num1 + num2;
  31.                 }
  32.  
  33.                 if (i == 1)
  34.                 {
  35.                     diff = 0;
  36.                 }
  37.  
  38.                 else if (i >= 2)
  39.                 {
  40.                     diff = Math.Abs(sumEven - sumOdd);
  41.  
  42.                     if (diff > max)
  43.                     {
  44.                         max = diff;
  45.                     }
  46.                 }
  47.  
  48.             }
  49.  
  50.             if (diff == 0)
  51.             {
  52.                 Console.WriteLine($"Yes, value={sumOdd}");
  53.             }
  54.             else
  55.             {
  56.                 Console.WriteLine($"No, maxdiff={max}");
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment