Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleApp1
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- List<int> numbers = Console.ReadLine().Split(", ").Select(int.Parse).ToList();
- int k = int.Parse(Console.ReadLine());
- Console.WriteLine(FindCount(numbers, k));
- }
- public static int FindCount(List<int> numbers, int k)
- {
- int result = 0;
- List<List<int>> array = new List<List<int>>();
- for (int i = 0; i < numbers.Count - 1; i++)
- {
- for (int j = i + 1; j < numbers.Count; j++)
- {
- if (numbers[i] + k == numbers[j])
- {
- result++;
- array.Add(new List<int>(new int[] { numbers[i], numbers[j] }));
- }
- }
- }
- var distinct = array.GroupBy(x => string.Join(",", x), (y, newArray) => newArray.First());
- return distinct.Count();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment