Cod sursa(job #879802)

Utilizator IronKingqwerty xxx IronKing Data 15 februarie 2013 21:21:13
Problema Generare de permutari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include <fstream>
using namespace std;
ifstream f("permutari.in"); ofstream g("permutari.out");
int k,v[10];
bool check(int p,int j) { bool ok=1; int l;
  for (l=1;l<=p-1;l++) {if (v[l]==j) {ok=0;} } return ok; };
void perm(int t) { int i;
  if (t<=k) {for (i=1;i<=k;i++) {if (check(t,i)==1) {v[t]=i;perm(t+1);} } }
  else {for (i=1;i<=k;i++) {g<<v[i]<<' ';} g<<'\n';} };
int main () {
  f>>k;
  perm(1); }