Advertisement
Josif_tepe

Untitled

Feb 14th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #define MAX 500
  3. int main()
  4. {
  5.     int n, m;
  6.     scanf("%d%d", &n, &m);
  7.     int mat[MAX][MAX];
  8.     for(int i = 0; i < n; i++) {
  9.         for(int j = 0; j < m; j++) {
  10.             scanf("%d", &mat[i][j]);
  11.         }
  12.     }
  13.     int k = (n * m) / 2;
  14.     int niza[k];
  15.     for(int i = 0; i < k; i++) {
  16.         scanf("%d", &niza[i]);
  17.     }
  18.     int zbir = 0;
  19.     int brojac = 0;
  20.     for(int i = 0; i < k; i++) {
  21.         int flag = 0;
  22.         for(int x = 0; x < n; x++) {
  23.             for(int y = 0; y < m; y++) {
  24.                 if(mat[x][y] == niza[i]) {
  25.                     zbir += mat[x][y];
  26.                     brojac++;
  27.                     flag = 1;
  28.                     mat[x][y] = 0;
  29.                     break;
  30.                 }
  31.             }
  32.             if(flag == 1) {
  33.                 break;
  34.             }
  35.         }
  36.        
  37.     }
  38.     printf("%d", zbir / brojac);
  39.    
  40.  
  41.     return 0;
  42. }
  43. /*
  44.  5 4
  45.  1 2 5 0
  46.  7 2 3 1
  47.  12 0 5 4
  48.  6 1 0 1
  49.  2 3 4 5
  50.  1 3 -2 5 14 13 7 8 9 11
  51.  */
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement