Cod sursa(job #489932)

Utilizator mike.Lumezeanu Mihai mike. Data 4 octombrie 2010 09:11:54
Problema Generare de permutari Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <iostream.h>
#include <fstream.h>

int x[100], n, k, i, m;

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

int cont (int k){
	
	int i;
	for (i=1;i<k;i++)
		if (x[i] == x[k])
			return 0;
		
	return 1;
}


void tipar () {

	int i;
	for (i=1;i<=m;i++)
		g<<x[i]<<"  ";
	g<<"\n";
}






int main () {
	
	f>>n;f>>m;
	k = 1; x[1] = 0;
	
	while (k)
		if (x[k] < n){
			x[k]++;
			if (cont (k))
				if (k == m)
					tipar ();
				else{
					k++;
					x[k] = 0;
				}
		}
		else
			k--;

	return 0;
}

f.close;
g.close;