Cod sursa(job #3208989)

Utilizator AndreiMLCChesauan Andrei AndreiMLC Data 1 martie 2024 17:42:58
Problema Generare de permutari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>

using namespace std;

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


const int nmax = 10;
int n;
int v[nmax];
int total = 1;

void citire()
{
    f >> n;
}

void solve()
{
    for (int i = 1; i <= n; i++)
    {
        v[i] = i;
        total *= i;
    }
    for (int i = 1; i <= total; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            g << v[j] << ' ';
        }
        g << '\n';
        next_permutation(v+1,v+1+n);
    }
}

int main()
{
    citire();
    solve();
}