Programming Question #: Looking for the top
Source: POJ (Coursera statement: The exercises completed on POJ will not count against the final results of Coursera. )
Note: Total time limit: 1000ms memory limit: 65536kB
Describe
On a mountain of MXN, the average elevation of each plot is known, and the plot of all the peaks is requested (the so-called peak, that is, the average elevation of its plots is not smaller than the average elevation of each parcel of four plots adjacent to the upper and lower sides of the block).
Input
The first line is two integers, representing the mountain's long M (5≤m≤20) and wide n (5≤n≤20).
The M behavior is followed by an integer matrix of MXN, representing the average elevation of each parcel. Each line is separated by a single space between the integers.
Output
Outputs the position of all top-most-located blocks. One per line. The first m-value from small to large, and then the N value from small to large order output.
Sample input
10 50 76 81 34 661 13 58 4 405 24 17 6 6513 13 76 3 208 36 12 60 3742 53 87 10 6542 25 47 41 3371 69 94 24 1292 11 71 3 82 91 90 20) 95 44
Sample output
0 20 42 12 43 03 24 35 25 47 28 08 49 3
#include <stdio.h>using namespacestd;intMain () {intm, N, I, J; scanf ("%d%d", &m, &N); intA[m][n]; for(i=0; i<m;i++) { for(j=0; j<n;j++) {scanf ("%d", &A[i][j]); } } for(i=0; i<m;i++) { for(j=0; j<n;j++) { BOOLShan =true; if(Shan && I-1>=0) { if(a[i][j]<a[i-1][j]) {Shan=false; } } if(Shan && i+1<m) {if(a[i][j]<a[i+1][j]) {Shan=false; } } if(Shan && J1>=0) { if(a[i][j]<a[i][j-1]) {Shan=false; } } if(Shan && j+1<N) {if(a[i][j]<a[i][j+1]) {Shan=false; } } if(Shan) {printf ("%d%d\n", I, J); } } } return 0;}
POJ C Programming Advanced Programming Question # #: Looking for the peak