WindFell

Pairs By Difference

Jun 5th, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. sing System;
  2. using System.Linq;
  3.  
  4. class PairsByDifference
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         string input = Console.ReadLine();
  9.         int difference = int.Parse(Console.ReadLine());
  10.  
  11.         int[] numbers = input
  12.             .Split()
  13.             .Select(int.Parse)
  14.             .ToArray();
  15.         int count = 0;
  16.  
  17.         for (int index = 0; index < numbers.Length - 1; index++)
  18.         {
  19.             for (int next = index + 1; next < numbers.Length; next++)
  20.             {
  21.                 if (numbers[index] - numbers[next] == difference
  22.                     || numbers[next] - numbers[index] == difference)
  23.                 {
  24.                     count++;
  25.                 }
  26.             }
  27.         }
  28.  
  29.         Console.WriteLine(count);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment