Pagini recente » Cod sursa (job #1909900) | Istoria paginii runda/7953532771521159 | Istoria paginii utilizator/vocakupe | Istoria paginii runda/001/clasament | Cod sursa (job #1869795)
#include <fstream>
using namespace std;
ifstream f("permutari.in");
ofstream g("permutari.out");
int n, p, k, x[101], i,pa=1;
void citire()
{
f>>n; p=n;
}
void afis()
{ pa=1;
for(int i = 1; i <= p; ++i)
if(x[i]) g<<i<<' ',pa=0;
if(!pa) g<<'\n';
}
void backtracking()
{
int k = 1;
x[k] = -1;
do
{
while(x[k] < 1)
{
x[k]++;
if(k==n)
afis();else
{
k++;
x[k] = -1;
}
}
k--;
}
while(k);
}
int main()
{
citire();
backtracking();
return 0;
}