Cod sursa(job #766856)

Utilizator mikeshadowIon Complot mikeshadow Data 12 iulie 2012 12:45:44
Problema Generare de permutari Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

ifstream afile ("permutari.in");
ofstream bfile ("permutari.out");

int n;

bool a[5];

void Back (int i, int level, string str)
{
	a[i]=true;
	string s;
	switch (i)
	{
	case 1: s="1";
		break;
	case 2: s="2";
		break;
	case 3: s="3";
		break;
	}
	str+=s+" ";
	for (int j=1; j<=3; j++)
		if (a[j]==false)
			Back (j,level+1,str);
	if (level==3) bfile<<str<<'\n';
	a[i]=false;
}


int main ()
{
	afile>>n;
	Back (1,1,"");
	Back (2,1,"");
	Back (3,1,"");
 return 0;   
}