Hey guys im trying to generate all possible string for a given pattern given a length and length of blocks.

For example if length=5 and the code was 2,1 then there must a block of 2 and then a block of 1 with at at least one gap between them. 'X' is a gap and 'Y' is a block

Here is what my program gives me:
YYXYX
XYYXY
YYXXY

So the way i do it right now is using binary strings from 00000 to 11111 and then prune off the ones that don't meet the code criteria. The problem is it has to work for lengths upto 30 and more complicated codes like 1,3,1,5,3 at this point the pruning gets a bit much anyone have a better method to generate the output?

Thanks

#include < stdio.h >
#include < stdlib.h >
#include < conio.h >

void main()
{
int option;
char sname[30];
int grade;


menu: clrscr();
printf("\nStudent Profile Program");
printf("\n\n\n[1] Add Student Profile");
printf("\n\n[2] View Student Profile");
printf("\n\n[3] Exit Program");
printf("\n \n\nEnter option: ");
scanf("%d", &option);
switch(option)
{
case 1:
{
clrscr();
printf("\nAdding Student Profile");
printf("\n\nEnter student name : ");
scanf("%s", &sname);
printf("\n\nEnter student grade: ");
scanf("%d", &grade);
goto menu;
}
case 2:
{
clrscr();
printf("\nViewing Student Profile");
printf("\n\nStudent name: %s", sname);
printf("\nStudent grade : %d", grade);
printf("\n\npress any key to go to menu...");
getch();
goto menu;
}
case 3:
{
clrscr();
printf("\nYou are about to exit the program...\npress any key to exit.");
getch();
exit(1);
}
default:
{
clrscr();
printf("\nInvalid value of option! \npress any key to go back to menu");
getch();
goto menu;
}
}

}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.