Pagini recente » Cod sursa (job #1759149) | Cod sursa (job #1453855) | Cod sursa (job #39439) | Cod sursa (job #866358) | Cod sursa (job #1669692)
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin ("partitii2.in");
ofstream fout ("partitii2.out");
/// toate partitiile de 2 submultimi disjuncte
int st[15], n;
int Deter_maxim(int top)
{
int maxim;
maxim = 0;
for (int i=1; i<=top; i++)
maxim = max(maxim, st[i]);
return maxim;
}
void Afisare()
{
int i, j, maxim, maximut;
maxim = Deter_maxim(n);
if (maxim != 2) return;
for (j=1; j<=maxim; j++)
{
fout << "{";
for (i=1; i<=n; i++)
if (st[i] == j) fout << i << " ";
fout << "}, ";
}
fout << endl;
}
void Back(int top)
{
int i;
if (top == n+1) Afisare();
else
for (i=1; i<=Deter_maxim(top-1)+1; i++)
{
st[top] = i;
Back(top+1);
}
}
int main ()
{
fin >> n;
cout << n;
Back(1);
fin.close();
fout.close();
system("pause");
return 0;
}