D_L3

sedlovi tochki

Jan 25th, 2024
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. bool isSmallestInRow(int row, int col, int** matrix, int rowsCount, int colsCount) {
  9.     for (int i = 0; i < colsCount; i++) {
  10.         if (matrix[row][col] > matrix[row][i]) {
  11.             return false;
  12.         }
  13.     }
  14.     return true;
  15. }
  16.  
  17. bool isBiggestInCol(int row, int col, int** matrix, int rowsCount, int colsCount) {
  18.     for (int i = 0; i < rowsCount; i++) {
  19.         if (matrix[row][col] < matrix[i][col]) {
  20.             return false;
  21.         }
  22.     }
  23.     return true;
  24. }
  25.  
  26. int* find(int** matrix, int rowsCount, int colsCount) {
  27.     int * result = new int[rowsCount];
  28.     int index = 0;
  29.     for (int i = 0; i < rowsCount; i++) {
  30.         for (size_t j = 0; j < colsCount; j++)
  31.         {
  32.             if (isSmallestInRow(i, j, matrix, rowsCount, colsCount) && isBiggestInCol(i, j, matrix, rowsCount, colsCount)) {
  33.                 result[index++] = matrix[i][j];
  34.             }
  35.         }
  36.     }
  37.  
  38.     int * finalResult = new int[index];
  39.     for (size_t i = 0; i < index; i++)
  40.     {
  41.         finalResult[i] = result[i];
  42.     }
  43.     return finalResult;
  44. }
  45.  
  46. int main() {
  47.    
  48.     return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment