Skip to content

Instantly share code, notes, and snippets.

@tmdroid
Created June 12, 2017 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmdroid/285b0427d24c497ca1aacec8e119e292 to your computer and use it in GitHub Desktop.
Save tmdroid/285b0427d24c497ca1aacec8e119e292 to your computer and use it in GitHub Desktop.
Crisztinel
#include <stdio.h>
int frec[10], st[10];
int k, n;
int verif() {
int i, j;
for(i = 0; i < k - 1; i++) {
for(j = i + 1; j < k; j++) {
if(st[i] == st[j]) return 0;
}
}
return 1;
}
void back(int l) {
if(l == k) {
if(verif()) {
int i;
for (i = 0; i < l; i++) {
printf("%d", st[i]);
}
printf("\n");
}
} else {
int i;
for (i = 0; i < 10; i++) {
if(frec[i]) {
st[l] = i;
back(l + 1);
}
}
}
}
int main() {
int nr[20];
int nrr = 0, i;
do {
scanf("%d", &n);
if(n == 0)
break;
nr[nrr++] = n;
} while(n != 0);
for(i = 0; i < nrr; i++) {
int x = nr[i];
while(x) {
int c = x % 10;
frec[c] = 1;
x = x / 10;
}
}
printf("k = ");
scanf("%d", &k);
back(0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment