You are on page 1of 2

using System;

namespace ConsoleApp
{
class Program
{
static bool ImaUzastopnih(bool[] daliElement)
{
bool prosliJe = false;
for (int i = 0; i < daliElement.Length; i++)
{
if (!daliElement[i])
prosliJe = false;
else if (daliElement[i] && !prosliJe)
{
prosliJe = true;
}
else if (daliElement[i] && prosliJe)
{
return false;
}
}
return true;
}
static void PSkup(bool[] daliElement)
{
if (!ImaUzastopnih(daliElement))
return;
bool pocetak = true;
Console.Write("{");
for (int i = 0; i < daliElement.Length; i++)
{
if (daliElement[i])
{
if (pocetak)
{
pocetak = false;
}
else
{
Console.Write(", ");
}
Console.Write("{0}", i);
}
}
Console.WriteLine("}");
}
static void PartitivniSkup(bool[] daliElement, int n)
{
if (n == 0)
{
PSkup(daliElement);
}
else
{
daliElement[n - 1] = true;
PartitivniSkup(daliElement, n - 1);
daliElement[n - 1] = false;
PartitivniSkup(daliElement, n - 1);
}
}
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
bool[] daliElement = new bool[n];
PartitivniSkup(daliElement, n);
}
}
}

You might also like