35. (matrix)
Returns the largest two-dimensional matrix (element and maximum) in a matrix. For example:
1 2 0 3 4
2 3 4 5 1
1 1 5 3 0
The largest in:
4 5
5 3
Requirements: (1) write algorithms; (2) analyze time complexity; (3) use C to write key code
In the morning, let's close the issue!
/* 35. returns the largest two-dimensional matrix (element and maximum) in a matrix ). for example, the largest of 1 2 0 3 42 3 4 5 11 1 5 3 0 is: 4 55 3 requirements: (1) write an algorithm; (2) analyze time complexity; (3) write key code in C */# include <stdio. h> // o (row * col) int summat (int * In, int row, int Col, int * r, int * c) {int sum = 0; for (INT I = 0; I <row-1; I ++) {int SUMT = 0; int * R1 = in + I * Col; int * r2 = in + (I + 1) * Col; For (Int J = 0; j <col-1; j ++) {SUMT = R1 [J] + R2 [J] + R1 [J + 1] + R2 [J + 1]; If (SUMT> sum) {* r = (I + 1); * c = (J + 1); sum = SUMT ;}} return sum ;} int main () {int A [15] = {,}; int sum, R, C; sum = summat (A, 3, 5, & R, & C); // r c returns the position of the largest two-dimensional matrix. Return 0 ;}
There is an improved method http://blog.csdn.net/jtlyuan/article/details/7467545 online
However, the time complexity is not significantly improved.