Advertisement
Josif_tepe

Untitled

Jun 8th, 2024
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <math.h>
  5.  
  6. int main(int argc, char * argv[]) {
  7.   int n, m;
  8.   scanf("%d%d", &n, &m);
  9.   int mat[n][m];
  10.   for(int i = 0; i < n; i++) {
  11.     for(int j = 0; j < m; j++) {
  12.         scanf("%d", &mat[i][j]);
  13.     }
  14.   }
  15.   int k;
  16.   scanf("%d", &k);
  17.     float sum = 0.0, kolku = 0;
  18.   for(int i = 0; i < k; i++) {
  19.     int a, b;
  20.     scanf("%d%d", &a, &b);
  21.    
  22.     if(a >= 0 && a < n && b >= 0 && b < m) {
  23.         sum += mat[a][b];
  24.         kolku++;
  25.     }
  26.   }
  27.  
  28.     printf("%f\n", sum / kolku);
  29. }
  30.  
  31.  
  32. /*
  33. 5 4
  34. 1 2 5 0
  35. 7 2 3 1
  36. 12 0 5 4
  37. 6  1 0 1
  38. 2 3 4 5
  39. 4
  40. 1 2
  41. 0 4
  42. 5 1
  43. 2 2
  44.  
  45. **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement