Cod sursa(job #2212598)

Utilizator pacheprotopopescuPake Protopopescu pacheprotopopescu Data 14 iunie 2018 15:13:45
Problema Generare de permutari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("permutari.in");
ofstream g("permutari.out");
int n,st[100];
int cond(int k)
{
    for(int i=1;i<=k-1;i++)
        if(st[k]==st[i])return 0;
    return 1;
}
void afisare(int k)
{
    for(int i=1;i<=k;i++)
        g<<st[i]<<" ";
    g<<"\n";
}
void bt()
{
    int k=1;
    st[k]=0;
    while(k>0)
    {
        st[k]++;
        if(st[k]<=n)
        {
            if(cond(k))if(k==n)afisare(k);
                else
                {
                    k++;
                    st[k]=0;
                }
        }
        else k--;
    }
}
int main()
{
    f>>n;
    bt();
}