#include <cstdio>
#include <cstring>
using namespace std;
const int MX = 1000;
int n, k;
char str[MX], partial[MX];
void solve(int pos, int aux) {
if(aux==k) {
partial[aux] = 0;
printf("%s\n", partial);
return;
}
for(int i = pos; i < n; i++) {
partial[aux] = str[i];
solve(i+1, aux+1);
}
}
int main() {
scanf("%s", str);
scanf("%d", &k);
n = strlen(str);
solve(0, 0);
}
On Jul 27, 7:49 pm, Rajeev Kumar <[email protected]> wrote:
> One more thread is running parallel on the same topic............
> Please refer :http://comments.gmane.org/gmane.comp.programming.algogeeks/17279
>
> On Wed, Jul 27, 2011 at 7:39 AM, Nikhil Gupta
> <[email protected]>wrote:
>
>
>
>
>
> > Given a string of length 5 (example "abcde"), write a program to print all
> > the possible combinations OF LENGTH 3.
>
> > In this case : abc, abd, abe, acd, ace, ade, bcd, bce, bde, cde
>
> > Can someone provide a working code?
>
> > --
> > Nikhil Gupta
> > Senior Co-ordinator, Publicity
> > CSI, NSIT Students' Branch
> > NSIT, New Delhi, India
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> Thank You
> Rajeev Kumar
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.