-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUva10189.cpp
More file actions
69 lines (65 loc) · 1.64 KB
/
Copy pathUva10189.cpp
File metadata and controls
69 lines (65 loc) · 1.64 KB
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
#include <iostream>
#include <math.h>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;
int main()
{
int rows,cols;
int field=1;
while(true){
scanf("%d %d",&rows,&cols);
if(rows==0 && cols==0) break;
vector<vector<char>> grid;
char ch;
for(int i=0;i<rows;i++){
vector<char> temp;
for(int j=0;j<cols;j++){
cin>>ch;
temp.push_back(ch);
}
grid.push_back(temp);
}
string arr[rows][cols];
int count=0;
for(int i=0;i<grid.size();i++){
for(int j=0;j<grid[i].size();j++){
if(grid[i][j]!='*'){
int x=i;int y=j;
for(int k=-1;k<2;k++){
for(int c=-1;c<2;c++){
if((x+k)>=0 && (x+k)<rows && (y+c)>=0 && (y+c)<cols){
if(grid[x+k][y+c]=='*')count++;
}
}
}
}
else{
arr[i][j]="*";
continue;
}
string ch=to_string(count);
arr[i][j]=ch;
count=0;
}
}
cout<<"Field #"<<field<<":"<<endl;
for(int i=0;i<rows;i++){
for(int j=0;j<cols;j++){
cout<<arr[i][j];
}
cout<<endl;
}
field++;
cout<<endl;
}
return 0;
}