Advertisement
Josif_tepe

Untitled

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