# PAT 08-2 to find the local maximum value of the matrix

Source: Internet
Author: User

The question is quite simple, but, one article per day. Say two: First, my carelessness led me to this spent maths a lot of time to find the wrong, see 4 test cases to three, I think that the boundary condition of the block is not considered, or there is a hidden logic or grammatical error, through the repeated comparison with other people's program is found to be my four more than the conditions of two write the same, There is one less, tragedy; second, flag with a bit awkward, with a cnt++ actually on the line, but the logic to express is whether the relationship, I still use bool, the problem set requirements and code implementation as follows

`1 /*2 Name:3 Copyright:4 Author:5 DATE:02/04/15 11:056 Description:7 given the integer matrix A of the M row N column, if the non-boundary element of a a[i][j] is greater than the next 4 elements, then the element A[i][j] is the local maximum value of the matrix. The subject requires the full local maxima of the given matrix and its location. 8 9 Input Format:Ten  One The input gives the number of rows m and the number of columns N (3<=m,n<=20) of matrix A in line 1th, and the last M row, each row gives the value of the N elements of a in that row. The numbers are separated by a space.  A  - output Format: -  the each line outputs a local maximum value in the format of the element value row number column number, where the row, column number starts with 1. It is required to increment the output by line number, and if the peer has more than 1 local maxima, the row is incremented by column number. If there is no local maximum, output the total number of rows with "None".  -  - Input Sample 1: - 4 5 + 1 1 1) 1 1 - 1 3 9) 3 1 + 1 5 3) 5 1 A 1 1 1) 1 1 at Output Example 1: - 9 2 3 - 5 3 2 - 5 3 4 - Input Sample 2: - 3 5 in 1 1 1) 1 1 - 9 3 9) 9 1 to 1 5 3) 5 1 + Output Example 2: - None 3 5 the */ *  \$#include <stdio.h>Panax Notoginseng#include <stdbool.h> -  the voidMaxium (intMintN); +  A intMain () the { + //freopen ("In.txt", "R", stdin);//For Test -      \$     intM, N; \$      -scanf"%d%d", &m, &N); -      the maxium (M, N); -     Wuyi //fclose (stdin);//For Test the      -     return 0; Wu } -  About voidMaxium (intMintN) \$ { -     intI, J, A[m][n]; -      -      for(i =0; i < M; i++) A          for(j =0; J < N; J + +) +scanf"%d", &a[i][j]); the          -     BOOLFlag; \$      theFlag =true; the      for(i =1; I < M-1; i++) the     { the          for(j =1; J < N-1; J + +) -         { in             if(A[i][j] > A[i-1][J] && A[i][j] > a[i][j +1] && A[i][j] > a[i +1][J] && A[i][j] > A[i][j-1]) the             { theprintf"%d%d%d\n", A[i][j], i +1, J +1); About                 if(flag) theFlag =false; the             } the         } +     } -     if(flag) theprintf"None%d%d\n", M, N);Bayi}`

PAT 08-2 to find the local maximum value of the matrix

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.