Cod sursa(job #2467478)

Utilizator ssebiStanciu Sebastian ssebi Data 4 octombrie 2019 14:54:39
Problema Generare de permutari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.44 kb
// InfoArenaCombinari.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

//#include "pch.h"
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int v[10];
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int maxNumber;

void toFile(int lenght) {
	for (int i = 0; i < lenght; i++) {
		fout << v[i]<<" ";
	}
	fout << '\n';
}

bool verif(int dim) {
	for (int i = 0; i < dim; ++i) {
		if (v[i] == v[dim]) {
			return 0;
		}
	}
	return 1;
}

void bkt(int dimensiune) {
	if (dimensiune == maxNumber) {
		toFile(maxNumber);
	}
	else {
		for (int i = 1; i <= maxNumber; i++)
		{
			v[dimensiune] = i;
			if (verif(dimensiune))
				bkt(dimensiune + 1);
		}
	}
}

int main()
{
	fin >> maxNumber;
	bkt(0);
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file