Advertisement
simonradev

MaxDifference

May 28th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 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 @byte
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int countOfRepeats = int.Parse(Console.ReadLine());
  14.            
  15.             int currentSum = 0;
  16.             int previousSum = 0;
  17.  
  18.             int maxDifference = 0;
  19.  
  20.             for (int currentRepeat = 0; currentRepeat < countOfRepeats; currentRepeat++)
  21.             {
  22.                 previousSum = currentSum;
  23.  
  24.                 int firstNumber = int.Parse(Console.ReadLine());
  25.                 int secondNumber = int.Parse(Console.ReadLine());
  26.  
  27.                 currentSum = firstNumber + secondNumber;
  28.  
  29.                 int difference = Math.Abs(currentSum - previousSum);
  30.  
  31.                 if (currentRepeat >= 1 && difference > maxDifference)
  32.                 {
  33.                     maxDifference = difference;
  34.                 }
  35.             }
  36.  
  37.             if (maxDifference == 0)
  38.             {
  39.                 Console.WriteLine($"Yes, value={currentSum}");
  40.             }
  41.             else
  42.             {
  43.                 Console.WriteLine($"No, maxdiff={maxDifference}");
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement