Advertisement
sazid_iiuc

Untitled

Feb 4th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. int main() {
  6.     //freopen ("10189.in", "r", stdin);
  7.     //freopen ("10189.out", "w", stdout);
  8.     //ifstream cin("10189.in");
  9.     //ofstream cout("10189.out");
  10.     int m, n, t = 0;
  11.  
  12.     while (true) {
  13.         cin >> m >> n;
  14.         char input[m][n];
  15.         int output[m][n] = {0};
  16.  
  17.         if (m == 0 && n == 0) break;
  18.         if(t > 0) cout << endl;
  19.  
  20.         for (int i = 0; i < m; i++) {
  21.             string line;
  22.             cin >> line;
  23.             for (int j = 0; j < n; j++) {
  24.                 input[i][j] = line[j];
  25.                 output[i][j] = 0;
  26.             }
  27.         }
  28.         for (int i = 0; i < m; i++) {
  29.             for (int j = 0; j < n; j++) {
  30.                 if (input[i][j] == '*') {
  31.                     if (i - 1 >= 0 && j - 1 >= 0) {
  32.                         output[i - 1][j - 1]++;
  33.                     }
  34.                     if (i - 1 >= 0 && j >= 0) {
  35.                         output[i - 1][j]++;
  36.                     }
  37.                     if (i - 1 >= 0 && j + 1 < n) {
  38.                         output[i - 1][j + 1]++;
  39.                     }
  40.                     if (j - 1 >= 0) {
  41.                         output[i][j - 1]++;
  42.                     }
  43.                     if (j + 1 < n) {
  44.                         output[i][j + 1]++;
  45.                     }
  46.                     if (i + 1 < m && j - 1 >= 0) {
  47.                         output[i + 1][j - 1]++;
  48.                     }
  49.                     if (i + 1 < m) {
  50.                         output[i + 1][j]++;
  51.                     }
  52.                     if (i + 1 < m && j + 1 < n) {
  53.                         output[i + 1][j + 1]++;
  54.                     }
  55.                     output[i][j] = 9;
  56.                 }
  57.             }
  58.         }
  59.         t++;
  60.         cout << "Field #" << t << ":" << endl;
  61.         for (int i = 0; i < m; i++) {
  62.             for (int j = 0; j < n; j++) {
  63.                 if (output[i][j] >= 9)
  64.                     cout << "*";
  65.                 else
  66.                     cout << output[i][j];
  67.             }
  68.             cout << endl;
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement