Advertisement
YavorGrancharov

Pairs_by_Difference

Oct 14th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 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()
  11.                 .Split(' ')
  12.                 .Select(int.Parse)
  13.                 .ToArray();
  14.  
  15.             int num = int.Parse(Console.ReadLine());
  16.  
  17.             int count = 0;
  18.             int diff = 0;
  19.             for (int i = 0; i < arr.Length - 1; i++)
  20.             {
  21.                 for (int j = i + 1; j < arr.Length; j++)
  22.                 {
  23.                     diff = Math.Abs(arr[i] - arr[j]);
  24.                     if(diff == num)
  25.                     {
  26.                         count++;
  27.                     }
  28.                 }                              
  29.             }
  30.             Console.WriteLine(count);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement