Cod sursa(job #3135197)

Utilizator sebuxSebastian sebux Data 2 iunie 2023 12:06:06
Problema Generare de permutari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <bits/stdc++.h>
#define optim ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define let auto
#define popcount __builtin_popcount
#define ctzll __builtin_ctzll
#define clzll __builtin_clzll

using namespace std;

ifstream fin("permutari.in");
ofstream fout("permutari.out");

int v[10];
bool p[10];
int n;
void back(int pos){
    for(int i = 1;i<=n;++i){
        if(!p[i]){
            p[i] = 1;
            v[pos] = i;
            if(pos == n){
                for(int i = 1;i<=n;++i){
                    fout<<v[i]<<' ';
                }
                fout<<'\n';
            }
            else back(pos + 1);
            p[i] = 0;
        }
    }
}


int main()
{

    fin>>n;
    back(1);


    return 0;
}