Advertisement
martinvalchev

Pairs_by_Difference

Feb 7th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Pairs_by_Difference
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  11.             int difrence = int.Parse(Console.ReadLine());
  12.             int counter = 0;
  13.  
  14.             for (int i = 0; i < arr.Length; i++)
  15.             {
  16.                 for (int j = i; j < arr.Length-1; j++)
  17.                 {
  18.                     if (Math.Abs(arr[i] - arr[j+1]) == difrence)
  19.                     {
  20.                         counter++;
  21.                     }
  22.                 }
  23.             }
  24.             Console.WriteLine(counter);
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement