A solution in java without arrays...
 
class Combinations
{

static ArrayList<String> words = new ArrayList<String>();

static void getCombinations(ArrayList<String> words)
{
 for(int j=0;j<words.length;word++)
 {
  //find the index of the word
  String word = words.get(j);
  //for each words, get the combinations for words AFTER IT
  for (int i=0;i<word.length;word++){
    //iterate thru the reamining words
    for(int m=j;m<words.size()-1;m++){
    //get the next word  
    String combWord =words.get(m);
 
    //now combine it with current 'LETTER' of this WORD
    for(int k=0;k<combWord.length;k++)
    {
    System.out.println(word.charAt(i)+combWord.charAt(k));
    }

    }
  }
 }
}

public static void main (String args[])
{
 words.add("ace");
 words.add("bowl");
 words.add("put");
 getCombinations(words);
}

}   
On Monday, October 1, 2012 8:47:48 AM UTC-7, ((** VICKY **)) wrote:

> No we don't need to care about repeated strings. :) Thanks for the 
> response folks. 
>
> On Mon, Oct 1, 2012 at 8:42 PM, saurabh agrawal 
> <saura...@gmail.com<javascript:>
> > wrote:
>
>> Do we need to handle cases when the same string will appear again??
>> In that case we can sort individual array and remove duplicates.
>>
>>
>> On Mon, Oct 1, 2012 at 9:54 AM, Rahul Singh <riit...@gmail.com<javascript:>
>> > wrote:
>>
>>> check this out.. 
>>>
>>> #include<iostream>
>>> #include<stdlib.h>
>>> using namespace std;
>>>
>>> void print_sets(string *s,int pos,int n,char *to_print)
>>> {
>>>     if(pos==n)
>>>     {
>>>         return;
>>>     }
>>>
>>>     for(int i=0;i<s[pos].length();i++)
>>>     {
>>>         to_print[pos] =  s[pos][i];
>>>         print_sets(s,pos+1,n,to_print);
>>>         if(pos==n-1)
>>>         {
>>>             for(int j=0;j<n;j++)cout<<to_print[j];
>>>             cout<<endl;
>>>         }
>>>     }
>>>     return;
>>> }
>>> int main()
>>> {
>>>     int n;
>>>     cin>>n;
>>>     string s[n];
>>>
>>>     for(int i=0;i<n;i++)
>>>     {
>>>         cin>>s[i];
>>>      }
>>>  char *to_print = new char[n];
>>>     print_sets(s,0,n,to_print);
>>> }
>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algo...@googlegroups.com<javascript:>
>>> .
>>> To unsubscribe from this group, send email to 
>>> algogeeks+...@googlegroups.com <javascript:>.
>>> For more options, visit this group at 
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Algorithm Geeks" group.
>> To post to this group, send email to algo...@googlegroups.com<javascript:>
>> .
>> To unsubscribe from this group, send email to 
>> algogeeks+...@googlegroups.com <javascript:>.
>> For more options, visit this group at 
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> -- 
> Cheers,
>  
>   Vicky
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/MbGDQZ6k2NEJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to