fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4.  
  5. int n, m, num, array[100][100] = {0};
  6. cin >> n >> m;
  7. for(int i = 0; i < n; i++)
  8. {
  9. for(int j = 0; j < m; j++)
  10. {
  11. cin >> array[i][j];
  12.  
  13. }
  14. }
  15. for(int i = 0; i < n; i++)
  16. {
  17. for(int j = 0; j < m; j++)
  18. {
  19. cout << array[i][j] << " ";
  20.  
  21. }
  22. cout << endl;
  23. }
  24. for(int i = 0; i < n; i++)
  25. {
  26. num = 0;
  27. for(int k = 0; k < 3; k++)
  28. {
  29.  
  30. for(int l = 0; l < 3; l++)
  31. {
  32.  
  33. if(k == 1 and l == 1)
  34. {
  35. continue;
  36. }
  37. if(array[i - 1 + k][0 - 1 + l] == 1)
  38. {
  39. num = num + 1;
  40.  
  41. }
  42.  
  43. }
  44. }
  45. cout << num;
  46. for(int j = 1; j < m; j++)
  47. {
  48.  
  49. num = 0;
  50. for(int k = 0; k < 3; k++)
  51. {
  52.  
  53. for(int l = 0; l < 3; l++)
  54. {
  55.  
  56. if(k == 1 and l == 1)
  57. {
  58. continue;
  59. }
  60. if(array[i - 1 + k][j - 1 + l] == 1)
  61. {
  62. num = num + 1;
  63.  
  64. }
  65.  
  66. }
  67. }
  68. cout << " " << num;
  69.  
  70.  
  71. }
  72. cout << endl;
  73. }
  74.  
  75.  
  76.  
  77. return 0;
  78. }
Success #stdin #stdout 0s 5296KB
stdin
8
stdout







0
0
0
0
0
0
0
0