Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ZeroSubset
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- int[] inputNumbers = { 1, 3, -4, -2, -1 };
- int combinationsCount = (1 << inputNumbers.Length) - 1;
- for (int i = 1; i < combinationsCount; i++)
- {
- var subset = new List<int>();
- for (int j = 0; j < inputNumbers.Length; j++)
- {
- if ((((1 << j) & i) >> j) == 1)
- {
- subset.Add(inputNumbers[j]);
- }
- }
- if (subset.Sum() == 0)
- {
- Console.WriteLine(string.Join(", ", subset));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement