fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4.  
  5. using size_type = std::size_t;
  6. using symbol_type = std::string;
  7. using char_type = typename symbol_type::value_type;
  8.  
  9. template< size_type n >
  10. struct test
  11. {
  12.  
  13. //static_assert(!(size_type('z' - 'a') + 1 < n));
  14.  
  15. void
  16. print(symbol_type const & _symbol) const
  17. {
  18. std::cout << _symbol << std::endl;
  19. }
  20.  
  21. bool
  22. operator () () const
  23. {
  24. symbol_type mishmash_(n, char_type('a' - 1));
  25. int cidx = 0;
  26. while (cidx >= 0) {
  27. if(cidx == n) {
  28. print(mishmash_);
  29. --cidx;
  30. } else {
  31. if(++mishmash_[cidx] == char_type('a' + n)) --cidx;
  32. else mishmash_[++cidx] = char_type('a' - 1);
  33. }
  34. }
  35. return true;
  36. }
  37.  
  38. };
  39.  
  40. int
  41. main()
  42. {
  43. test< 3 > const test_{};
  44. if (test_()) {
  45. std::cout << "Succes!" << std::endl;
  46. return EXIT_SUCCESS;
  47. } else {
  48. std::cerr << "Failure!" << std::endl;
  49. return EXIT_FAILURE;
  50. }
  51. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
aaa
aab
aac
aba
abb
abc
aca
acb
acc
baa
bab
bac
bba
bbb
bbc
bca
bcb
bcc
caa
cab
cac
cba
cbb
cbc
cca
ccb
ccc
Succes!