Cod sursa(job #1287831)

Utilizator Vally77FMI Calinescu Valentin Gelu Vally77 Data 8 decembrie 2014 08:57:35
Problema Generare de permutari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.69 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream ka("permutari.in");
ofstream ki("permutari.out");
int n, v[10], t;

void afisare()
{
    for(int i = 1; i <= n; i++)
        ki << v[i] << " ";
    ki << '\n';
}

void back(int k)
{
    if(k == n)
        afisare();
    else
    {
        for(int i = 1; i <= n; i++)
        {
            bool gasit = false;
            for(int j = 1; j <= k && !gasit; j++)
                if(v[j] == i)
                    gasit = true;
            if(!gasit)
            {
                v[k + 1] = i;
                back(k + 1);
            }
        }
    }
}

int main()
{
    ka >> n;
    back(0);
}