1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <string>
void print_stuff(int min_n, int max_n)
{
struct local
{
static void build_stuff(
int min_n, int max_n, int cur_n,
int cur_c, int max_c, bool inc,
std::string & ret)
{
if (cur_c == max_c)
{
if (cur_n == min_n && !inc) return;
ret += '\n';
if (cur_n == max_n) inc = false;
int new_n = inc ? cur_n + 1 : cur_n - 1;
return build_stuff(
min_n, max_n, new_n,
0, new_n, inc, ret);
}
ret += '0' + cur_n;
return build_stuff(
min_n, max_n, cur_n,
cur_c + 1, max_c, inc, ret);
}
};
std::string stuff;
local::build_stuff(
min_n, max_n, min_n,
0, min_n, true, stuff);
std::cout << stuff;
}
int main()
{
print_stuff(1,9);
return 0;
}
|