suppose I have been given strings "abc", "def" and "ghi", I want to generate all the possible combination of word generated by picking from these strings. for eg for "abc", "def" and "ghi"
we should get
"adg","adh","adi","aeg","aeh","aei","afg","afh","afi", "bdg","bdh","bdi","beg","beh","bei","bfg","bfh","bfi", "cdg","cdh","cdi","ceg","ceh","cei","cfg","cfh","cfi"
How to Do it.
my attampt...
vector<string> wordset;
for(int i = 0; i < digits.size(); i++ )
{
wordset.push_back( latters[digits[i] - '0'] );
}
for(int i = 0; i < wordset.size()-2; i++ )
{
string word = wordset[i];
for(int j = 0; j < word.size(); j++ )
{
string combn = "";
combn += word[j];
for(int k = 0; k < wordset[i+1].size(); k++ )
{
combn += wordset[i+1][k];
for(int l = 0; l < wordset[i+2].size(); l++ )
{
combn += wordset[i+2][l];
ans.push_back(combn);
combn = "";
combn += word[j];
combn += wordset[i+1][k];
}
}
}
}