Cod sursa(job #189629)

Utilizator Dr.OptixCristian Dinu Dr.Optix Data 16 mai 2008 13:38:39
Problema Generare de permutari Scor 0
Compilator c Status done
Runda Arhiva educationala Marime 1.14 kb
/* ========================================================================== */
/*                                                                            */
/*   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>
#include <vector>
#include <algorithm>

int 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()));
}