Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <stdio.h>
- #include <algorithm>
- using namespace std;
- int* a;
- int m,n;
- void create(int **pa, int* pn, int* pm){
- printf("n = ");
- scanf("%d", &n);
- printf("m = ");
- scanf("%d", &m);
- a = (int*)malloc(sizeof(int)*m*n);
- for(int i=0;i<n*m;++i){
- scanf("%d", &a[i]);
- }
- *pa = a;
- *pn = n;
- *pm = m;
- }
- void printArr(int *a){
- printf("исходный массив = \n");
- for(int i=0;i<n;++i){
- for(int j=0;j<m;++j){
- printf(" %d", *(a+i*m+j));
- }
- printf("\n");
- }
- }
- int max_even(int *a){
- int mx=0;
- for(int i=0;i<n;++i){
- int current = 0;
- for(int j=0;j<m;++j){
- if(*(a+m*i+j) % 2 == 0){
- ++current;
- }
- }
- mx = max(mx, current);
- }
- return mx;
- }
- int count_sum(int* a){
- int ans = 0;
- int mx = max_even(a);
- for(int i=0;i<n;++i){
- int current = 0, sum = 0;
- for(int j=0;j<m;++j){
- sum+=*(a+m*i+j);
- if(*(a+m*i+j) % 2 == 0){
- ++current;
- }
- }
- if(current == mx){
- ans+=sum;
- }
- }
- return ans;
- }
- double sr(int* a){
- double ans = 0, col =0;
- for(int i=0;i<n;++i){
- for(int j=0;j<i;++j){
- if(*(a+m*i+j)%2 == 0){
- ans+=*(a+m*i+j);
- ++col;
- }
- }
- }
- if(col == 0){
- return 0;
- }else{
- return (1.0*ans)/col;
- }
- }
- int main()
- {
- create(&a, &n, &m);
- printArr(a);
- printf("ответ на задание = %d\n", count_sum(a));
- printf("ответ на доп задание = %lf\n", sr(a));
- free(a);
- return 0;
- }
- //2 3
- //1 2 3
- //4 5 6
- //4 4
- //2 4 1 3
- //0 6 8 1
- //0 0 1 5
- //6 4 4 9
- //2 3
- //1 3 5
- //9 9 9
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement