警示后人
查看原帖
警示后人
983647
__LYC__qwq楼主2023/7/13 15:01

搜索40分

#include<bits/stdc++.h>

using namespace std;

const int N = 200, dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};

int v[N][N], n, m;

char a[N][N];

void S(int x, int y){
  if(x < 1 || x > n || y < 1 || y > m || v[x][y]){
    return;
  }
  v[x][y] = 1;
  if(a[x][y] != '*'){
    int o = 0;
    for(int i = x - 1; i <= x + 1; ++i){
      for(int j = y - 1; j <= y + 1; ++j){
        if(a[i][j] == '*'){
          o++;
        }
      }
    }
    a[x][y] = o + '0';
  }
  for(int i = 0; i < 4; ++i){
    S(x + dx[i], y + dy[i]);
  }
  v[x][y] = 0;
}

int main(){
  cin >> n >> m;
  for(int i = 1; i <= n; ++i){
    for(int j = 1; j <= m; ++j){
      cin >> a[i][j];
    }
  }
  S(1, 1);
  for(int i = 1; i <= n; ++i){
    for(int j = 1; j <= m; ++j){
      cout << a[i][j];
    }
    cout << '\n';
  }
  return 0;
}

2023/7/13 15:01
加载中...