Cod sursa(job #3153467)

Utilizator David2007David Preda David2007 Data 29 septembrie 2023 18:57:23
Problema Generare de permutari Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.53 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("permutari.in");
ofstream g("permutari.out");

int st[20], n, cnt;

void Afisare(){
    cnt++;
    if(cnt == 1) return;
    for(int i = 1; i <= n; i++)
        if(st[i] == 1) g << i << " ";
    g << "\n";
}
void Back(int top){
    int i;
    if(top == n + 1)
        Afisare();
    else {
        for(i = 0; i <= 1; i++){
            st[top] = i;
            Back(top + 1);
        }
    }
}
int main()
{
    f >> n;
    Back(1);
    return 0;
}