Advertisement
debono

Untitled

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