HI I have a series(sorted), which i require to create combinations. I am not getting the good code for doing this. My series should generate the following combinations... Please help me in getting this in C++. Thanks for your help.
A:
A
A B:
A
B
A B
A B C:
A
B
C
AB
AC
BC
ABC
A B C D:
A
B
C
D
AB
AC
AD
BC
BD
CD
ABC
ABD
ACD
BCD
ABCD
A B C D E:
A
B
C
D
E
AB
AC
AD
AE
BC
BD
BE
CD
CE
DE
ABC
ABD
ABE
ACD
ACE
ADE
BCD
BCE
BDE
CDE
ABCDE
and so on....
Sounds like a school assignment!
How far have you progressed....post your code
Hint 1. How many permutations of series A,B,C,D,E would you expect? 5!?
Hint 2. Use the standard C++ generic algorithm next_permutation(s.s+?) if you can`t write your own.
It looks something like this:
1 2 3 4 5 6
char* s="abcd";
for(int i=0;i<24;i++)
{
next_permutation(s,s+4)
cout<<(i%8?'\t':'\n')<<s;//prints eight combinations to a line starting with abdc
}
The function requires the <algorithm> #include file.
You will have to work out how to get the subset combinations yourself.
hth's