Advertisement
ostapdontstop

Untitled

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