Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- int n, m;
- scanf("%d%d", &n, &m);
- int mat[n][m];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- scanf("%d", &mat[i][j]);
- }
- }
- int polovina = (n * m) / 2;
- int sum = 0, brojac = 0;
- for(int k = 0; k < polovina; k++) {
- int x;
- scanf("%d", &x);
- int ok = -1;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- if(mat[i][j] == x) {
- sum += mat[i][j];
- brojac++;
- mat[i][j] = 0;
- ok = 1;
- break;
- }
- }
- if(ok == 1) {
- break;
- }
- }
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- printf("%d ", mat[i][j]);
- }
- printf("\n");
- }
- printf("%d\n", sum / brojac);
- return 0;
- }
- /*
- 5 4
- 1 2 5 0
- 7 2 3 1
- 12 0 5 4
- 6 1 0 1
- 2 3 4 5
- 1 3 -2 5 14 13 7 8 9 11
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement