Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main(int argc, char *argv[]) {
  8.     int matrix[4][5];
  9.  
  10.     cout << "Enter the elements of array: " << endl << endl;
  11.     for (int j = 0; j < (sizeof(matrix) / sizeof(*matrix)); j++) {
  12.         for (int i = 0; i < (sizeof(matrix[0]) / sizeof(*matrix[0])); i++) {
  13.             cin >> matrix[j][i];
  14.         }
  15.  
  16.         if (j != ((sizeof(matrix) / sizeof(*matrix)) - 1)) {
  17.             cout << "------------------" << endl;
  18.         } else {
  19.             cout << endl;
  20.             cout << "==================" << endl;
  21.             cout << endl;
  22.         }
  23.     }
  24.  
  25.     vector<int> passes;
  26.     for (int j = 0; j < (sizeof(matrix) / sizeof(*matrix)); j++) {
  27.         for (int i = 0; i < (sizeof(matrix[0]) / sizeof(*matrix[0])); i++) {
  28.             if (matrix[j][i] < 0) {
  29.                 passes.push_back(j);
  30.             }
  31.         }
  32.     }
  33.  
  34.     vector<int> results;
  35.     int num;
  36.     for (int j = 0; j < passes.size(); j++) {
  37.         num = 0;
  38.         for (int i = 0; i < (sizeof(matrix[0]) / sizeof(*matrix[0])); i++) {
  39.             num += matrix[passes[j]][i];
  40.         }
  41.         results.push_back(num);
  42.     }
  43.  
  44.     if (results.size() != 0) {
  45.         int num = 0;
  46.  
  47.         for (int i = 0; i < results.size(); i++) {
  48.             if (results[i] > num) {
  49.                 num = results[i];
  50.             }
  51.         }
  52.  
  53.         cout << "Result is " << num << endl;
  54.     } else {
  55.         cout << "Not found" << endl;
  56.     }
  57.  
  58.     cout << endl;
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement