Can any1 pls tell me wat is wrng wit d following C++ program: #include<iostream>
using namespace std; main() { long int k; int no; cin>>no; while(no>0) { int n; cin>>n; cin>>k; int a[3][n],bin[n],size[3]; for(int j=0;j<3;j++) {size[j]=0; for(int i=0;i<n;i++) {bin[i]=0;a[j][i]=0;} } long int tmp=k; for(int i=n-1;tmp>0;i--) { bin[i]=((tmp+2)%2); tmp/=2; } for(int i=0,pos;i<n;i++) { if(i==0) { if(bin[i]==0) pos=0; else pos=1; a[pos][i]=n; size[pos]++; continue; } else { if(bin[i]==bin[i-1]) { a[pos][size[pos]]=n-i; size[pos]++; } else { if(bin[i]==0) { if ((i%2)==1) pos=((pos+1)%3); else pos=(((pos-1)+3)%3); } else { if ((i%2)==0) pos=((pos+1)%3); else pos=(((pos-1)+3)%3); } a[pos][size[pos]]=n-i; size[pos]++; } } } for(int i=0;i<3;i++) { cout<<i+1<<": "; for(int j=0;j<size[i];j++) { if(j!=0){cout<<"|";}cout<<a[i][j]; } cout<<endl; } no--; } } I cross checked it wit recursive algorithm too.but still it shows wrong answer Probably some test case failure .. can ny1 identify it ?? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@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.