tanya_zheleva

10

Jan 31st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ExamPreparation
  5. {
  6.     class Startup
  7.     {
  8.         static void Main()
  9.         {
  10.             int[] numbers = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  11.                 .Select(int.Parse)
  12.                 .ToArray();
  13.             int diff = int.Parse(Console.ReadLine());
  14.             int found = 0;
  15.  
  16.             for (int i = 0; i < numbers.Length; i++)
  17.             {
  18.                 for (int j = i; j < numbers.Length; j++)
  19.                 {
  20.                     if (Math.Abs(numbers[i] - numbers[j]) == diff)
  21.                     {
  22.                         found++;
  23.                     }
  24.                 }
  25.             }
  26.  
  27.             Console.WriteLine(found);
  28.         }
  29.     }
  30. }
Add Comment
Please, Sign In to add comment