fork download
  1. #include <algorithm>
  2. #include <iterator>
  3.  
  4. template<class data_iter>
  5. bool next_combination(data_iter data_begin, data_iter data_end, typename std::iterator_traits<data_iter>::value_type alph_begin, typename std::iterator_traits<data_iter>::value_type alph_end)
  6. {
  7. if (data_begin==data_end) return false;
  8. data_iter data_cur = data_begin;
  9. while (++*data_cur == alph_end) {
  10. *data_cur = alph_begin;
  11. ++data_cur;
  12. if (data_cur == data_end)
  13. return false;
  14. }
  15. return true;
  16. }
  17.  
  18. #include <iostream>
  19.  
  20. int main()
  21. {
  22. char data[] = {'A', 'A', 'A', '\0'};
  23. do {
  24. std::cout << data << '\n';
  25. } while(next_combination(data+0, data+3, 'A', 'C'));
  26. return 0;
  27. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
AAA
BAA
ABA
BBA
AAB
BAB
ABB
BBB