fork download
  1. #include <iostream>
  2. using namespace std;
  3. int main(){
  4. int maze[102][102]={0};
  5. int total[102][102]={0};
  6. int r,c;
  7. cin>>r>>c;
  8. for(int i=1;i<=r;i++){
  9. for(int j=1;j<=c;j++){
  10. cin>>maze[i][j];
  11. }
  12. }
  13. for(int i=1;i<=r;i++){
  14. for(int j=1;j<=c;j++){
  15. total[i][j]=0;
  16. for(int a=i-1;a<=i+1;a++){
  17. for(int b=j-1;b<=j+1;b++){
  18. total[i][j]+=maze[a][b];
  19. }
  20. }
  21. total[i][j]-=maze[i][j];
  22. }
  23. }
  24. bool first=true;
  25. for(int i=1;i<=r;i++){
  26. if(first) first=false;
  27. else cout<<endl;
  28. for(int j=1;j<=c;j++){
  29. cout<<total[i][j];
  30. if(j==c) continue;
  31. else cout<<" ";
  32. }
  33. //cout<<endl;
  34. }
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0.01s 5496KB
stdin
3 3
0 0 1
1 0 1
1 0 1
stdout
1 3 1
1 5 2
1 4 1