Advertisement
bacco

Еднакви двойки . for loops

Jan 29th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2.  
  3. namespace tESt
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.  
  10.             var n = int.Parse(Console.ReadLine());
  11.  
  12.             var lastPair = 0;  
  13.             var maxDiff = 0;  
  14.  
  15.             for (int i = 0; i < n; i++)  
  16.             {
  17.                 var num1 = int.Parse(Console.ReadLine());  
  18.                 var num2 = int.Parse(Console.ReadLine());  
  19.  
  20.                 var curentPair = num1 + num2;  
  21.  
  22.                 if (i > 0)    
  23.                 {
  24.                     if (lastPair != curentPair)  
  25.                     {
  26.                         var diff = Math.Abs(curentPair - lastPair);  
  27.  
  28.                         if (diff > maxDiff)  
  29.                         {
  30.                             maxDiff = diff;  
  31.                         }
  32.                     }
  33.                 }
  34.                 lastPair = curentPair;
  35.             }
  36.             if (maxDiff == 0)    
  37.             {
  38.                 Console.WriteLine($"Yes, value={lastPair}");
  39.             }
  40.             else    
  41.             {
  42.                 Console.WriteLine($"No, maxdiff={maxDiff}");
  43.             }
  44.              
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement