ostapdontstop

massive-2_2

Jan 19th, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int m=3, n=3;
  8.     int a[m][n] = {
  9.         {1,1,3},
  10.         {4,5,6},
  11.         {7,2,5}
  12.     };
  13.  
  14.     for (int i = 0; i < m; ++i){
  15.         for (int j = 0; j < n; ++j){
  16.             // a[i][j] = i*n+j;
  17.             cout<< setw(2) <<a[i][j]<<'\t';}
  18.         cout<<endl;
  19.     }
  20.     for (int i = 0; i < 12; ++i) cout<<'-';
  21.  
  22.     int min, max;
  23.  
  24.     bool hasMin, hasMax;
  25.     hasMin = hasMax = 0;
  26.  
  27.     for (int i = 0, j, _min; i < m; ++i) {
  28.         _min = hasMin ? min:a[i][0];
  29.  
  30.         for (j = 0 ; j < n; ++j){
  31.             if (a[i][j]%2 == 0) break;
  32.             if (a[i][j] < _min) _min = a[i][j];
  33.         }
  34.         if (j==n) {
  35.             min = _min;
  36.             hasMin = true;
  37.             }
  38.     }
  39.  
  40.     for (int j = 0, chet = 0, nech = 0, _max ; j < n; ++j) {
  41.         _max = hasMax ? max:a[0][j];
  42.  
  43.         for (int i = 0 ; i < m; ++i){
  44.             if (a[i][j] > _max) _max = a[i][j];
  45.             if (a[i][j]%2 == 0) chet++;
  46.             else nech++;
  47.         }
  48.         if (nech>chet) {
  49.             hasMax = true;
  50.             max = _max;
  51.         }
  52.     }
  53.     if (hasMin) cout<<endl<<"min:" << setw(2) << min;
  54.     else cout<<endl<< "netu_min";
  55.  
  56.     if (hasMax) cout<<endl<<"max:" << setw(2) << max;
  57.     else cout<<endl<< "netu_max";
  58.  
  59.     if (hasMin && hasMax) cout<<endl<<"z = "<< min + max;
  60.     else cout<<endl<< "netu_z";
  61. }
Add Comment
Please, Sign In to add comment