NHAPMON - BAI15

PPAP_1264589 · updated January 25, 2021 · C++
#include <bits/stdc++.h>
using namespace std;
int n,m;
bool check(int a[101][101], int i, int j){
    int t = 0;
    for (int k = i-1; k >= 1; k--){
        if (a[k][j] > a[i][j]) {
            t++;
            break;
        }
    }
    for (int k = i+1; k <= n; k++){
        if (a[k][j] > a[i][j]) {
            t++;
            break;
        }
    }
    for (int k = j-1; k >= 1; k--){
        if (a[i][k] > a[i][j]) {
            t++;
            break;
        }
    }
    for (int k = j+1; k <= m; k++){
        if (a[i][k] > a[i][j]) {
            t++;
            break;
        }
    }
    return (t < 4);
}


int main()
{
    freopen ("inp.txt", "r", stdin);
    freopen ("out.txt", "w", stdout);
    int a[101][101];
    int y = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            cin >> a[i][j];
        }
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            if (check(a,i,j)) y++;
        }
    }
    cout << y;
    return 0;
}

Comments

Please sign up or log in to contribute to the discussion.