#include <iostream>
// print the number if it is a three digit number with unique digits
void print_if_unique_three_digit_number( unsignedint number )
{
// determine the three digits
constunsignedint a = number/100 ;
constunsignedint b = (number/10) % 10 ;
constunsignedint c = number%10 ;
// if first digit is non-zero and the three digits are distinct, print it
if( a != 0 && a != b && b != c && c != a ) std::cout << number << '\n' ;
}
// print all three digit numbers with unique digits formed by the digits [ 0, max_digit ]
void print_all_unique_three_digit_numbers( unsignedint max_digit = 5, unsignedint num_digits = 0, unsignedint number_so_far = 0 )
{
// we have a number formed from the requisite number of digits, print it if it qualifies
if( num_digits == 3 ) print_if_unique_three_digit_number(number_so_far) ;
else // less than three digits, append one more digit and try again
{
for( unsignedint i = 0; i <= max_digit ; ++i ) // for each possible digit
print_all_unique_three_digit_numbers( max_digit, num_digits+1, number_so_far*10 + i ) ;
}
}
int main()
{
print_all_unique_three_digit_numbers(5) ; // digits chosen from [ 0, 1, 2, 3, 4, 5 ]
}
#include <bits/stdc++.h>
usingnamespace std;
int main() {
string str = "012345";
set<string> s;
do {
string ss = "";
for (int i = 0; i < 3; ++i) {
ss = ss + str[i];
}
if (ss[0] != '0') {
s.insert(ss);
}
} while (next_permutation(str.begin(), str.end()));
cout << s.size();
for (auto i : s) {
cout << i << endl;
}
return EXIT_SUCCESS;
}
#include <iostream>
#include <string>
#include <set>
usingnamespace std;
string toBase( int n, int base )
{
return n == 0 ? "" : toBase( n / base, base ) + to_string( n % base );
}
bool noRepeats( string s )
{
set<char> S( s.begin(), s.end() );
return S.size() == s.size();
}
int main()
{
int start = 38, end = 215;
for ( int n = start; n <= end; n++ )
{
string s = toBase( n, 6 );
if ( noRepeats( s ) ) cout << s << '\n';
}
}
#include <iostream>
int main() {
// Interpretting n as base 6
for (int n = 0; n < 216; n++) {
int a = n / 36;
int b = n / 6 % 6;
int c = n % 6;
if (a!=b && a!=c && b!=c)
std::cout << a << b << c << '\n';
}
}