題目來源:judgegirl from ntu prof. pangfeng Liu
Write a function to evaluate for a lot of and . The prototype of the function is as follows.
1 int
evaluate_f(
int
*iptr[],
int
n,
int
*index);
Each pointer in iptr
points to an array of two integers. The first integer is , and the second integer is . The length of the pointer array is , so there are pairs of and that you need to evaluate . Compute these and return the maximum as the return value of evaluate_f
. Also you need to set index so that it becomes the index into iptr
where the maximum happens. If the maximum value can be evaluated from multiple pairs, set the index to be the smallest among them. For example, if the and pointed by iptr[3]
and iptr[5]
both have the maximum , then evaluate_f
should return and index should be set to . Variable is always positive.
Input format
n > 0
Sample Input
We may test your program in the following code:
12345678910111213 #include <stdio.h>
#include "evaluate_f.h"
int
main(){
int
a[] = { 9, 7 };
int
b[] = { 3, 2 };
int
c[] = { 3, 2 };
int
d[] = { 9, 7 };
int
*iptr[] = { a, b, c, d };
int
max, index;
max = evaluate_f(iptr, 4, &index);
printf
(
"%d %d\n"
, max, index);
}
Sample Output
0 1