@Gene I think there is some mistake in this programe. when the input is : a[ ] = {30,25,19,16} b[ ] = {20,18,14,10}
the right result should be 30+20, 30+18, 25+20,30+14 but the output of your programe is 30+20,30+18,25+20,25+18 Best Regards! 2010/5/4 Gene <gene.ress...@gmail.com> > > > I propose this solution (it's C89): > > #include <stdio.h> > > //int a[] = { 8, 7, 4, 3, 2, 1, 1, 1, 1, 1 }; > //int b[] = { 34, 23, 21, 19, 15, 13, 11, 8, 4, 2 }; > > int a[] = { 6, 5, 4, 3, 2, 1 }; > int b[] = { 9, 8, 6, 5, 3, 2 }; > > void find_pairs(int *a, int *b, int n) > { > int iamax[100], ibmax[100], i, ia, ib; > > for (i = 0; i < n; i++) > iamax[i] = ibmax[i] = -1; > > ia = ib = 0; > for (i = 0; i < n; i++) { > printf("(%d,%d)\n", a[ia], b[ib]); > if (a[ia + 1] + b[ibmax[ia + 1] + 1] > b[ib + 1] + > a[iamax[ib + 1] + > 1]) > ib = ++ibmax[++ia]; > else > ia = ++iamax[++ib]; > } > } > > int main(void) > { > find_pairs(a, b, sizeof a / sizeof a[0]); > return 0; > } > > -- > 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<algogeeks%2bunsubscr...@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 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.