-
Notifications
You must be signed in to change notification settings - Fork 0
/
075b.cpp
100 lines (95 loc) · 2.75 KB
/
075b.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint998244353;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = a; i <= (int)(b); i++)
#define rng(i,a,b) for(int i = a; i < (int)(b); i++)
#define rrng(i,a,b) for(int i = a; i >= (int)(b); i--)
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define si(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define ret(x) { cout<<(x)<<endl;}
typedef long long ll;
using namespace std;
using P = pair<ll,ll>;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
ll mul(ll a, ll b) { if (a == 0) return 0; if (LINF / a < b) return LINF; return min(LINF, a * b); }
ll mod(ll x, ll y){return (x % y + y) % y;}
ll inttoc(ll x){return x + '0';}
bool isvalid(int x, int y, int H, int W) {
if(0 <= x && x < H && 0 <= y && y < W) {return true;}
else {return false;}
}
int main(){
ll h,w;
cin >> h >> w;
vector<string> s(h);
rep(i,h){
cin >> s[i];
}
vector<vector<char>> ans(h,vector<char>(w));
rep(i,h){
rep(j,w){
if(s[i][j] == '.'){
ll p = 0;
if(isvalid(i,j-1,h,w)){
if(s[i][j-1] == '#'){
p++;
}
}
if(isvalid(i-1,j-1,h,w)){
if(s[i-1][j-1] == '#'){
p++;
}
}
if(isvalid(i-1,j,h,w)){
if(s[i-1][j] == '#'){
p++;
}
}
if(isvalid(i-1,j+1,h,w)){
if(s[i-1][j+1] == '#'){
p++;
}
}
if(isvalid(i,j+1,h,w)){
if(s[i][j+1] == '#'){
p++;
}
}
if(isvalid(i+1,j+1,h,w)){
if(s[i+1][j+1] == '#'){
p++;
}
}
if(isvalid(i+1,j,h,w)){
if(s[i+1][j] == '#'){
p++;
}
}
if(isvalid(i+1,j-1,h,w)){
if(s[i+1][j-1] == '#'){
p++;
}
}
char c = p + '0';
ans[i][j] = c;
}
else{
ans[i][j] = '#';
}
}
}
rep(i,h){
rep(j,w){
cout << ans[i][j];
}
cout << endl;
}
return 0;
}