it is easy to rewrite the whole code correctly than finding a bug in this code. don't ask someone else to debug your codes, else you will get !!!!
On Mon, Oct 3, 2011 at 7:03 PM, g4ur4v <gauravyadav1...@gmail.com> wrote: > Original question=> http://www.codechef.com/problems/WORDS1 > > code=> > > #include<stdio.h> > #include<string.h> > #include<stdlib.h> > //#include<conio.h> > > > int compare(const void *a,const void *b) > { > const char *a_=*(const char **)a; > const char *b_=*(const char **)b; > return(strcmp((char *)a_,(char *)b_)); > } > int main() > { > int t,n,i,j,k,sts=0; > char **A; > char Bi[1000]; > > > > scanf("%d",&t); // input number of test cases > while(t--) > { > scanf("%d",&n); //input number of strings for each > test case > A=new char*[n]; > for(i=0;i<n;++i) > { > > scanf("%s",Bi); //input the strings > int l=strlen(Bi); > A[i]=new char[l]; > strcpy(A[i],Bi); > } > // delete Bi; > > > qsort(A,n,sizeof(char*),compare); //sorting the > strings > > > bool B[n]; > > for(i=0;i<n;++i) > B[i]=true; > > > int f=1; > char s,e; > > > for(j=0;j<n;++j) > { > s=A[j][0]; > B[j]=false; > e=A[j][strlen(A[j])-1]; > > for(i=0;i<n;++i) > { > if(B[i]) > { > if(A[i][0]==e) > { > B[i]=false; > e=A[i][strlen(A[i])-1]; > ++f; > i=0; > } > } > } > if(f==n) > { > printf("Ordering is possible.\n"); > sts=1; > goto outside; > > } > > > for(k=0;k<n;++k) > B[k]=true; > f=1; > } > // delete []B; > > outside: > > if(sts==0) > printf("The door cannot be opened.\n"); > > } > > > } > > > > > > TEST CASES > 1) 1 > 2 > ok > ok > output=>The door cannot be opened. > (so the code works fine for this case.) > > 2) 2 > 2 > directi > codechef > 3 > skenzo > logicboxes > orderbox > output=>The door cannot be opened. > Ordering is possible. > (so the code works fine for this case too.) > > 3)3 > 2 > directi > codechef > 3 > skenzo > logicboxes > orderbox > 2 > ok > ok > > the code doesnt give output and stops responding as soon as 3 case > starts processing.. > > > Plz...explain why is this happening and how to rectify this code... > Plz..reply asap. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > 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. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. 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.