The problem is simple. From given set of digits (there are max 10 digits), compute all numbers that can be madeform this digits (a digit can be used as many times it's is included in the set).
Fist I think of using brute force and running through all possible combinations, but the number of combinations is as big as factorial of N, where N is the number of digits. And even if it's possible how can I run though all possible combinations withouit using 10 for loops?
Second I tried to put all those digits in a string and the erasing one from the string and putting on the end and keep trying like this, but this probably won't give any possible combinations and even if it does I don't believe it'll be in a reasonable time.
I'm sure there must be a quicker and better algorithm for getting all possibles nubmers from a given set of digits.
I found one code on th Internet and it's:
#include <iostream>
#include <algorithm>
using namespace std;
int main () {
int noOfDigits;
cin >> noOfDigits;
int myints[noOfDigits];
for(int i = 0; i<noOfDigits; i++)
{
cin >> myints[i];
}
sort (myints,myints+3);
do {
for(int i = 0; i<noOfDigits;i++)
{
cout << myints[i];
}
cout << endl;
} while ( next_permutation(myints,myints+noOfDigits) );
return 0;
}