import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main (String[] args) throws FileNotFoundException, IOException {
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb=new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
StringTokenizer st=new StringTokenizer(line,";");
StringTokenizer st2=new StringTokenizer(st.nextToken(),",");
int n=Integer.parseInt(st2.nextToken());
int m=Integer.parseInt(st2.nextToken());
StringBuilder str=new StringBuilder(st.nextToken());
int[][]arr=new int[n+2][m+2];
char[][]val=new char[n+2][m+2];
for(int i=1;i<n+1;i++){
for(int j=1;j<m+1;j++){
val[i][j]=str.charAt(0);
if(val[i][j]=='*'){
inc(arr, i, j);
}
str.deleteCharAt(0);
}
}
for(int i=1;i<n+1;i++){
for(int j=1;j<m+1;j++){
if(val[i][j]=='*'){
sb.append(val[i][j]);
}else{
sb.append(arr[i][j]);
}
}
}
sb.append('\n');
}
System.out.print(sb);
}
static void inc(int[][]arr,int x,int y){
for(int i=x-1;i<x+2;i++){
arr[i][y-1]++;
if(i!=x)
arr[i][y]++;
arr[i][y+1]++;
}
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main (String[] args) throws FileNotFoundException, IOException {
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb=new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
StringTokenizer st=new StringTokenizer(line,";");
StringTokenizer st2=new StringTokenizer(st.nextToken(),",");
int n=Integer.parseInt(st2.nextToken());
int m=Integer.parseInt(st2.nextToken());
StringBuilder str=new StringBuilder(st.nextToken());
int[][]arr=new int[n+2][m+2];
char[][]val=new char[n+2][m+2];
for(int i=1;i<n+1;i++){
for(int j=1;j<m+1;j++){
val[i][j]=str.charAt(0);
if(val[i][j]=='*'){
inc(arr, i, j);
}
str.deleteCharAt(0);
}
}
for(int i=1;i<n+1;i++){
for(int j=1;j<m+1;j++){
if(val[i][j]=='*'){
sb.append(val[i][j]);
}else{
sb.append(arr[i][j]);
}
}
}
sb.append('\n');
}
System.out.print(sb);
}
static void inc(int[][]arr,int x,int y){
for(int i=x-1;i<x+2;i++){
arr[i][y-1]++;
if(i!=x)
arr[i][y]++;
arr[i][y+1]++;
}
}
}
No comments:
Post a Comment