Advertisement
bacco

Pairs by Difference

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