Advertisement
j0nze

Equal Pairs

Nov 4th, 2017
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 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 looper = 0;
  16.             int sum = 0;
  17.             int prevSum = 0;
  18.             int maxDiff = 0;
  19.             int diff = 0;
  20.  
  21.             while (looper < n)
  22.             {
  23.                 int num1 = int.Parse(Console.ReadLine());
  24.                 int num2 = int.Parse(Console.ReadLine());
  25.  
  26.                 sum = num1 + num2;
  27.  
  28.                 if (sum != prevSum && looper != 0)
  29.                 {
  30.                     diff = Math.Abs(sum - prevSum);
  31.                 }
  32.                 if (diff > maxDiff)
  33.                 {
  34.                     maxDiff = diff;
  35.                 }
  36.  
  37.                 prevSum = sum;
  38.                 looper++;
  39.             }
  40.             if (maxDiff == 0)
  41.             {
  42.                 Console.WriteLine("Yes, value={0}",sum);
  43.             }
  44.             else
  45.             {
  46.                 Console.WriteLine("No, maxdiff={0}",maxDiff);
  47.             }                                
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement