#include <iostream>
#include <string>
#include <vector>
 
bool increase(const std::vector<std::string>& 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[index].size()) {
            it[index] = 0;
        } else {
            return true;
        }
    }
    return false;
}
 
void do_job(const std::vector<std::string>& v, std::vector<std::size_t>& it)
{
    for (std::size_t i = 0, size = v.size(); i != size; ++i) {
        std::cout << v[i][it[i]];
    }
    std::cout << std::endl;
}
 
void iterate(const std::vector<std::string>& v)
{
    std::vector<std::size_t> it(v.size(), 0);
 
    do {
        do_job(v, it);
    } while (increase(v, it));
}
 
int main()
{
    const std::vector<std::string> v{"b", "ACD", "12"};
    iterate(v);
}