fork download
  1. #include <iterator>
  2.  
  3. template<class it, class mather=std::plus<typename std::iterator_traits<it>::value_type> >
  4. bool next_increasing(it start, it end, typename std::iterator_traits<it>::value_type limit, mather plus={}) {
  5. bool n = true;
  6. it c = std::prev(end);
  7. *c = plus(*c, 1);
  8. if (*c == limit) {
  9. if (c == start)
  10. return false;
  11. n = next_increasing<it>(start, c, plus(limit,-1));
  12. it prev = std::prev(c);
  13. *c = plus(*prev,1);
  14. }
  15. return n;
  16. }
  17. template<class it, class mather=std::plus<typename std::iterator_traits<it>::value_type> >
  18. bool next_increasing_eq(it start, it end, typename std::iterator_traits<it>::value_type limit, mather plus={}) {
  19. bool n = true;
  20. it c = std::prev(end);
  21. *c = plus(*c, 1);
  22. if (*c == limit) {
  23. if (c == start)
  24. return false;
  25. n = next_increasing_eq<it>(start, c, limit);
  26. it prev = std::prev(c);
  27. *c = *prev;
  28. }
  29. return n;
  30. }
  31.  
  32. #include <iostream>
  33.  
  34. int main() {
  35. int data[5] = {0,1,2,3,4};
  36. do {
  37. std::cout << data[0]<<data[1]<<data[2]<<data[3]<<data[4]<<'\n';
  38. }while(next_increasing(data+0,data+5,10));
  39. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
01234
01235
01236
01237
01238
01239
01245
01246
01247
01248
01249
01256
01257
01258
01259
01267
01268
01269
01278
01279
01289
01345
01346
01347
01348
01349
01356
01357
01358
01359
01367
01368
01369
01378
01379
01389
01456
01457
01458
01459
01467
01468
01469
01478
01479
01489
01567
01568
01569
01578
01579
01589
01678
01679
01689
01789
02345
02346
02347
02348
02349
02356
02357
02358
02359
02367
02368
02369
02378
02379
02389
02456
02457
02458
02459
02467
02468
02469
02478
02479
02489
02567
02568
02569
02578
02579
02589
02678
02679
02689
02789
03456
03457
03458
03459
03467
03468
03469
03478
03479
03489
03567
03568
03569
03578
03579
03589
03678
03679
03689
03789
04567
04568
04569
04578
04579
04589
04678
04679
04689
04789
05678
05679
05689
05789
06789
12345
12346
12347
12348
12349
12356
12357
12358
12359
12367
12368
12369
12378
12379
12389
12456
12457
12458
12459
12467
12468
12469
12478
12479
12489
12567
12568
12569
12578
12579
12589
12678
12679
12689
12789
13456
13457
13458
13459
13467
13468
13469
13478
13479
13489
13567
13568
13569
13578
13579
13589
13678
13679
13689
13789
14567
14568
14569
14578
14579
14589
14678
14679
14689
14789
15678
15679
15689
15789
16789
23456
23457
23458
23459
23467
23468
23469
23478
23479
23489
23567
23568
23569
23578
23579
23589
23678
23679
23689
23789
24567
24568
24569
24578
24579
24589
24678
24679
24689
24789
25678
25679
25689
25789
26789
34567
34568
34569
34578
34579
34589
34678
34679
34689
34789
35678
35679
35689
35789
36789
45678
45679
45689
45789
46789
56789