Cod sursa(job #3246360)

Utilizator cosminteoaTeodorescu Cosmin cosminteoa Data 2 octombrie 2024 19:51:59
Problema Generare de permutari Scor 80
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <bits/stdc++.h>
#define NMAX 8
using namespace std;
ifstream fin( "permutari.in" );
ofstream fout( "permutari.out" );
int n;
int f[NMAX];
int v[NMAX];
void perm( int i ){
  int j;
  if( i == 0 ){
    for( j = n; j > 0; j-- )
      fout << v[j] << " ";
    fout << "\n";
  }else{
    for( j = 1; j <= n; j++ )
      if( f[j] == 0 ){
        f[j] = 1;
        v[i] = j;
        perm( i - 1 );
        f[j] = 0;
      }
  }
}
int main()
{
    fin >> n;
    perm( n );
    return 0;
}