Pagini recente » Cod sursa (job #1017814) | Cod sursa (job #3120690) | Cod sursa (job #162227) | Cod sursa (job #395044) | Cod sursa (job #189631)
Cod sursa(job #189631)
/* ========================================================================== */
/* */
/* Permutari.c */
/* (c) 2008 Dr.Optix */
/* */
/* This is an implementation of the algorithm witch computes all permutaions*/
/* of the {1, 2, ...N} array. */
/* ========================================================================== */
//include the headers
#include <iostream.h>
#include <vector.h>
#include <algorithm.h>
void main () {
//open the files
freopen("permutari.in", "r", stdin);
freopen("permutari.out", "w", stdout);
int N;
vector<int> v;
//generate the {1, 2, ...N} array
cin >> N;
for (int i = 1; i <= N; ++i)
v.push_back(i);
//compute and write down all permutations
do {
for (int i = 0; i < N; ++i)
cout << v[i] << ' ';
cout << '\n';
} while (next_permutation(v.begin(), v.end()));
}