Advertisement
Guest User

10.PairsByDifference

a guest
Oct 10th, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 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 _10.PairsByDifference
  8. {
  9.     class PairsByDifference
  10.     {
  11.         static void Main()
  12.         {
  13.             int[] numbers = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  14.             int difference = int.Parse(Console.ReadLine());
  15.  
  16.             int cntr = 0;
  17.  
  18.             for (int i = 0; i < numbers.Length; i++)
  19.             {
  20.                 for (int j = 1; j < numbers.Length; j++)
  21.                 {
  22.                     int result = Math.Max(numbers[i], numbers[j]) - Math.Min(numbers[i], numbers[i]);
  23.  
  24.                     if (result == difference)
  25.                     {
  26.                         cntr++;
  27.                     }
  28.                 }
  29.             }
  30.  
  31.             Console.WriteLine(cntr);
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement