Advertisement
pifka

Combinations without Repetition

Sep 8th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApp4
  6. {
  7. class Program
  8. {
  9. static char[] elements;
  10. static char[] vari;
  11. static int set;
  12.  
  13. public static void Comb(int index, int start)
  14. {
  15. if (index >= set)
  16. {
  17. Console.WriteLine(string.Join(" ", vari));
  18. }
  19.  
  20. else
  21. {
  22. for (int i = start; i < elements.Length; i++)
  23. {
  24. vari[index] = elements[i];
  25.  
  26. Comb(index + 1, i + 1);
  27. }
  28. }
  29. }
  30.  
  31. static void Main(string[] args)
  32. {
  33. elements = Console.ReadLine().Split().Select(char.Parse).ToArray();
  34. set = int.Parse(Console.ReadLine());
  35.  
  36. vari = new char[set];
  37.  
  38. Comb(0, 0);
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement