// L-23 MCS 360 Fri 15 Oct 2010 : enumerate_words

#include <iostream>
#include <vector>
using namespace std;

void enumerate_words 
       ( int k, int n,
         vector<string> &s, string &a );

// enumerates all combinations of n characters,
// one character from each string,
// starting at k (call with k = 0),
// accumulates the result in the string a.

int main()
{
   cout << "give number of words : ";
   int n; cin >> n;

   cin.ignore(numeric_limits<int>::max(),'\n');

   vector<string> words;
   for(int i=0; i<n; i++) 
   {
      cout << "word[" << i << "] : ";
      string w;
      getline(cin,w,'\n');
      words.push_back(w);
   }
   cout << "the words :";
   for(int i=0; i<n; i++) 
      cout << " " << words[i];
   cout << endl;

   string r = "";
   for(int i=0; i<n; i++) r = r + " ";
   cout << "combinations :";
   enumerate_words(0,n,words,r);
   cout << endl;

   return 0;
}

void enumerate_words ( int k, int n, vector<string> &s, string &a )
{
   if(k == n)
      cout << " " << a;
   else
   {
      for(int i=0; i<s[k].size(); i++)
      {
         a[k] = s[k][i];
         enumerate_words(k+1,n,s,a);
      }
   }
}

