44 lines
909 B
C
44 lines
909 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
// Expect t to be a non empty list of columns. Expect res to be of size 2
|
|
void f(const int *t, uint rows, uint cols, int res[2]) {
|
|
int i = (rows * cols) - 1;
|
|
int i_max = i;
|
|
while (i > 0) {
|
|
i--;
|
|
if (t[i] >= t[i_max]) {
|
|
i_max = i;
|
|
}
|
|
}
|
|
res[0] = i_max % cols;
|
|
res[1] = i_max / cols;
|
|
}
|
|
|
|
void print_t(const int t[], uint len) {
|
|
if (len == 0) {
|
|
printf("[]");
|
|
return;
|
|
}
|
|
uint i = 1;
|
|
printf("[%d", t[0]);
|
|
while (i < len) {
|
|
printf(", %d", t[i]);
|
|
i++;
|
|
}
|
|
printf("]");
|
|
}
|
|
|
|
int main() {
|
|
int t[][3] = {{2, 9, 4}, {7, 5, 3}, {6, 1, 8}};
|
|
int res[2];
|
|
f(t[0], 3, 3, res);
|
|
|
|
printf("t = [\n");
|
|
print_t(t[0], 3);
|
|
printf(",\n");
|
|
print_t(t[1], 3);
|
|
printf(",\n");
|
|
print_t(t[2], 3);
|
|
printf("\n]\nMaximum : (%d, %d)\n", res[0], res[1]);
|
|
} |