Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- using namespace std;
- void output (struct obj &);
- struct obj {
- int val;
- bool cond;
- string name;
- };
- int main()
- {
- int m=3, n=3, a[m][n];
- for (int i = 0; i < m; ++i){
- for (int j = 0; j < n; ++j){
- a[i][j] = 1+rand()%8;
- cout<< setw(2) <<a[i][j]<<'\t';
- }
- cout<<endl;
- }
- for (int i = 0; i < 12; ++i) cout<<'-';
- struct obj max, min, z;
- max.name = "max";
- min.name = "min";
- z.name = " z";
- for (int i = 0, j, _min; i < m; ++i) {
- _min = min.cond ? min.val:a[i][0];
- for (j = 0 ; j < n; ++j){
- if (a[i][j]%2 != 0) break;
- _min = a[i][j] < _min ? a[i][j]:_min;
- }
- if (j==n) {
- min.val = _min;
- min.cond = true;
- }
- }
- for (int j = 0, chet = 0, nech = 0, _max ; j < n; ++j) {
- _max = max.cond ? max.val:a[0][j];
- for (int i = 0 ; i < m; ++i){
- _max = a[i][j] > _max ? a[i][j]:_max;
- if (a[i][j]%2 == 0) chet++;
- else nech++;
- }
- if (chet>nech) {
- max.cond = true;
- max.val = _max;
- }
- }
- z.cond = max.cond * min.cond;
- z.val = min.val + max.val;
- output(min);
- output(max);
- output(z);
- }
- void output (struct obj &a){
- if (a.cond) cout<< endl <<a.name<<": "<< setw(2) << a.val;
- else cout<<endl<< "netu " << a.name;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement