Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Tran Viet Anh - 9:33PM
- #include<iostream>
- #include<string.h>
- using namespace std;
- int main()
- {
- cout << "Input number of row: ";
- int n; cin >> n;
- cout << "Input number of column: ";
- int m; cin >> m;
- int a[n][m];
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- {
- cout << "a[" << i << "," << j << "]: ";
- cin >> a[i][j];
- }
- int maxRow[n];
- int minColumn[m];
- int countMax[n];
- int countMin[m];
- for (int i = 0; i < n; i++)
- {
- countMax[i] = 0;
- maxRow[i] = -INT_MAX;
- }
- for (int j = 0; j < m; j++)
- {
- countMin[j] = 0;
- minColumn[j] = INT_MAX;
- }
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- {
- if (a[i][j] > maxRow[i])
- {
- countMax[i] = 1;
- maxRow[i] = a[i][j];
- }
- else if (a[i][j] == maxRow[i]) countMax[i]++;
- if (a[i][j] < minColumn[j])
- {
- countMin[j] = 1;
- minColumn[j] = a[i][j];
- }
- else if (a[i][j] == minColumn[j]) countMin[j]++;
- }
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- if (a[i][j] == maxRow[i] && countMax[i] == 1 && a[i][j] == minColumn[j] && countMin[j] == 1)
- cout << a[i][j] << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement