Pagini recente » Cod sursa (job #2899845) | Cod sursa (job #2738754) | Cod sursa (job #203098) | Cod sursa (job #2063174) | Cod sursa (job #1599736)
// Day6V2.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("submultimi.in");
ofstream g("submultimi.out");
int st[20], n, m = 1;
void afisare() {
for (int i = 1; i <= m; ++i)
cout << st[i] << " ";
cout << "\n";
}
int valid(int k) {
for (int i = 1; i < k; ++i) {
if (st[i] == st[k] || st[k] > st[k - 1])
return 0;
}
return 1;
}
void BK(int k) {
for (int i = 1; i <= n; ++i) {
st[k] = i;
if (valid(k))
if (k == m)
afisare();
else
BK(k + 1);
}
}
int main()
{
f >> n;
while (m <= n) {
BK(1);
++m;
}
return 0;
}