Advertisement
Wow_Rasl

Untitled

Dec 13th, 2021
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <stdio.h>
  4. #include <algorithm>
  5. using namespace std;
  6. int* a;
  7. int m,n;
  8. void create(int **pa, int* pn, int* pm){
  9.     printf("n = ");
  10.     scanf("%d", &n);
  11.     printf("m = ");
  12.     scanf("%d", &m);
  13.     a = (int*)malloc(sizeof(int)*m*n);
  14.     for(int i=0;i<n*m;++i){
  15.         scanf("%d", &a[i]);
  16.     }
  17.     *pa = a;
  18.     *pn = n;
  19.     *pm = m;
  20. }
  21.  
  22. void printArr(int *a){
  23.     printf("исходный массив = \n");
  24.     for(int i=0;i<n;++i){
  25.         for(int j=0;j<m;++j){
  26.             printf(" %d", *(a+i*m+j));
  27.         }
  28.         printf("\n");
  29.     }
  30. }
  31.  
  32. int max_even(int *a){
  33.     int mx=0;
  34.     for(int i=0;i<n;++i){
  35.         int current = 0;
  36.         for(int j=0;j<m;++j){
  37.             if(*(a+m*i+j) % 2 == 0){
  38.                 ++current;
  39.             }
  40.         }
  41.         mx = max(mx, current);
  42.     }
  43.     return mx;
  44. }
  45.  
  46. int count_sum(int* a){
  47.     int ans = 0;
  48.     int mx = max_even(a);
  49.     for(int i=0;i<n;++i){
  50.         int current = 0, sum = 0;
  51.         for(int j=0;j<m;++j){
  52.             sum+=*(a+m*i+j);
  53.             if(*(a+m*i+j) % 2 == 0){
  54.                 ++current;
  55.             }
  56.         }
  57.         if(current == mx){
  58.             ans+=sum;
  59.         }
  60.     }
  61.     return ans;
  62. }
  63.  
  64. double sr(int* a){
  65.     double ans = 0, col =0;
  66.     for(int i=0;i<n;++i){
  67.         for(int j=0;j<i;++j){
  68.             if(*(a+m*i+j)%2 == 0){
  69.                 ans+=*(a+m*i+j);
  70.                 ++col;
  71.             }
  72.         }
  73.     }
  74.     if(col == 0){
  75.         return 0;
  76.     }else{
  77.         return (1.0*ans)/col;
  78.     }
  79. }
  80.  
  81. int main()
  82. {
  83.     create(&a, &n, &m);
  84.     printArr(a);
  85.     printf("ответ на задание = %d\n", count_sum(a));
  86.     printf("ответ на доп задание = %lf\n", sr(a));
  87.     free(a);
  88.     return 0;
  89. }
  90.  
  91. //2 3
  92. //1 2 3
  93. //4 5 6
  94.  
  95.  
  96. //4 4
  97. //2 4 1 3
  98. //0 6 8 1
  99. //0 0 1 5
  100. //6 4 4 9
  101.  
  102. //2 3
  103. //1 3 5
  104. //9 9 9
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement