VPanev

Untitled

Jun 10th, 2022
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApp1
  6. {
  7. internal class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> numbers = Console.ReadLine().Split(", ").Select(int.Parse).ToList();
  12. int k = int.Parse(Console.ReadLine());
  13.  
  14. Console.WriteLine(FindCount(numbers, k));
  15. }
  16.  
  17. public static int FindCount(List<int> numbers, int k)
  18. {
  19. int result = 0;
  20.  
  21. List<List<int>> array = new List<List<int>>();
  22.  
  23. for (int i = 0; i < numbers.Count - 1; i++)
  24. {
  25. for (int j = i + 1; j < numbers.Count; j++)
  26. {
  27. if (numbers[i] + k == numbers[j])
  28. {
  29. result++;
  30. array.Add(new List<int>(new int[] { numbers[i], numbers[j] }));
  31. }
  32. }
  33. }
  34. var distinct = array.GroupBy(x => string.Join(",", x), (y, newArray) => newArray.First());
  35.  
  36. return distinct.Count();
  37. }
  38. }
  39. }
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment