static void Main(string[] args)
        {
            Console.WriteLine("Enter numbers, separated by a comma: ");
            int[] numbers = Console.ReadLine()
                .Split(new char[] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(x => int.Parse(x))
                .Where(x => x != 0)
                .OrderBy(x => x)
                .ToArray();

            Console.WriteLine("Enter SUM: ");
            int sum = int.Parse(Console.ReadLine());

            Console.WriteLine(@"Enter elements count
(If you dont'want to set the count, press Enter): ");
            string inputCount = Console.ReadLine();
            int? elementCount;
            if (String.IsNullOrWhiteSpace(inputCount))
            {
                elementCount = null;
            }
            else
            {
                elementCount = int.Parse(inputCount);
            }

            SubsetGenerator generator = new SubsetGenerator(numbers, sum);
            string result = generator.GetResult(elementCount);
            if (String.IsNullOrWhiteSpace(result))
                result = String.Format("No subsets with sum {0} were found!", sum);

            Console.WriteLine(result);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter numbers, separated by a comma: ");
            int[] numbers = Console.ReadLine()
                            .Split(new char[] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries)
                            .Select(x => int.Parse(x))
                            .Where(x => x != 0)
                            .OrderBy(x => x)
                            .ToArray();

            Console.WriteLine("Enter SUM: ");
            int sum = int.Parse(Console.ReadLine());

            Console.WriteLine(@"Enter elements count
(If you dont'want to set the count, press Enter): ");
            string inputCount = Console.ReadLine();
            int?   elementCount;

            if (String.IsNullOrWhiteSpace(inputCount))
            {
                elementCount = null;
            }
            else
            {
                elementCount = int.Parse(inputCount);
            }

            SubsetGenerator generator = new SubsetGenerator(numbers, sum);
            string          result    = generator.GetResult(elementCount);

            if (String.IsNullOrWhiteSpace(result))
            {
                result = String.Format("No subsets with sum {0} were found!", sum);
            }

            Console.WriteLine(result);
        }