Advertisement
wojiaocbj

E5-B cbj2

Apr 1st, 2023
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. /*
  2.  Author: 曹北健(37509)
  3.  Result: AC Submission_id: 5310407
  4.  Created at: Sat Apr 01 2023 17:25:55 GMT+0800 (China Standard Time)
  5.  Problem: 6810  Time: 12    Memory: 2152
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <math.h>
  12. #include <ctype.h>
  13. #include <time.h>
  14. #pragma warning(disable:4996 6031)
  15. int a[128][128] = { 0 };
  16.  
  17. int main(){
  18.     int m, n, i, j, dx, dy;
  19.     scanf("%d%d", &m, &n);
  20.     for(i = 0; i < m; i++){
  21.         for(j = 0; j < n; j++){
  22.             scanf("%d", &(a[i][j]));
  23.         }
  24.     }
  25.     for(i = 0; i < m; i++){
  26.         for(j = 0; j < n; j++){
  27.             int cnt = 0;
  28.             double sum = 0;
  29.             for(dx = -1; dx <= 1; dx++){
  30.                 for(dy = -1; dy <= 1; dy++){
  31.                     if((i + dx >= 0) && (i + dx < m) && (j + dy >= 0) && (j + dy < n)){
  32.                         sum += a[i + dx][j + dy];
  33.                         cnt += 1;
  34.                     }
  35.                 }
  36.             }
  37.             printf("%3d ", (int)round(sum / cnt));
  38.         }
  39.         putchar('\n');
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement