i need to complete the following structure so
it will print all the str strings in length n,that follows ththe following rules:
A.the strings have only a,b,c chars
B.a string could not have two consecutive 'a' chars
C.a sting could not have 3 consecutive 'c' chars
for example:
for n=3
it will print
aba,abb,abc,aca,acb,acc,bab,bac,bba,bbb,bbc,bca,bc b,bcc,cab,
cac,cba,cbb,cbc,cca,ccb,
and returns 21
what each block should doCode:#include<stdio.h> #define N 3 int printStrings(int i, int n, char* str, int a, int c){ int count=0; if (?? 1 ??) { printf("%s,",str); ?? 2 ??; } if (?? 3 ??) a=0; else{ str[i] = 'a'; count += ?? 4 ??; } ?? 5 ??; count += printStrings(i+1,n,str,a,c); if (c==2) ?? 6 ??; else{ str[i] = 'c'; count += ?? 7 ??; } ?? 8 ??; } void main(){ char str[N+1]; str[N] = '\0'; printf("%d\n",printStrings(0,N,str,0,0)); }
i think that each block is a given condition
for example the following block is linked with the rule that we are not allowed 3 'c' in a row
but dont know what it should do in general?
Code:if (c==2) ?? 6 ??; else{ str[i] = 'c'; count += ?? 7 ??; }



LinkBack URL
About LinkBacks


