Решение с использованием жесткого кода будет выглядеть следующим образом:
const char choices[] = {'a', 'b', 'c'};
for (int a1 : choices) {
for (int a2 : choices) {
for (int a3 : choices) {
for (int a4 : choices) {
for (int a5 : choices) {
do_job(a1, a2, a3, a4, a5);
}
}
}
}
}
Вы можете использовать следующее для обобщенного c пути (все a
с в векторе):
template <typename T>
bool increase(const std::vector<T>& v, std::vector<std::size_t>& it)
{
for (std::size_t i = 0, size = it.size(); i != size; ++i) {
const std::size_t index = size - 1 - i;
++it[index];
if (it[index] >= v.size()) {
it[index] = 0;
} else {
return true;
}
}
return false;
}
template <typename T>
void do_job(const std::vector<T>& v, const std::vector<std::size_t>& it)
{
for (const auto e : it) {
std::cout << v[e] << " ";
}
std::cout << std::endl;
}
template <typename T>
void iterate(const std::vector<T>& v, std::size_t size)
{
std::vector<std::size_t> it(size, 0);
do {
do_job(v, it);
} while (increase(v, it));
}
Демо