fork download
  1. import java.io.*;
  2.  
  3. public class Main{
  4.  
  5. public static void main (String []ar) throws IOException {
  6.  
  7.  
  8.  
  9. int n,m,con=0;
  10. int [][] matrizentera;
  11. String [][] matriz;
  12. String [][] matrizre;
  13. n=1;
  14. m=1;
  15.  
  16. while (n!=0 && m!=0)
  17. {
  18. String linea1;
  19. linea1=b.readLine();
  20. String [] V1 =new String[linea1.length()];
  21. V1=linea1.split(" ");
  22.  
  23. n=Integer.parseInt(V1[0]);
  24. m=Integer.parseInt(V1[1]);
  25.  
  26.  
  27. if (n!=0 && m!=0)
  28. {
  29. con++;
  30. if (con>1)
  31. {
  32. System.out.println("");
  33. }
  34.  
  35. matriz=new String [n+2][m+2];
  36. matrizre=new String [n+2][m+2];
  37. matrizentera=new int [n+2][m+2];
  38.  
  39. for(int s=0;s<n+2;s++)
  40. {
  41. for (int j=0;j<m+2;j++)
  42. {
  43. matriz[s][j]=".";
  44. }
  45. }
  46.  
  47. for(int s=0;s<n+2;s++)
  48. {
  49. for (int j=0;j<m+2;j++)
  50. {
  51. matrizentera[s][j]=0;
  52. }
  53. }
  54.  
  55.  
  56. for(int x=1;x<n+2;x++)
  57. {
  58. String linea;
  59. linea=b.readLine();
  60. String [] V =new String[linea.length()];
  61. V=linea.split("");
  62.  
  63. for (int y=1;y<m+2;y++)
  64. {
  65. matriz[x][y]=V[y-1];
  66. if (y==m)
  67. {
  68. break;
  69. }
  70. } if (x==n)
  71. {
  72. break;
  73. }
  74. }
  75.  
  76.  
  77.  
  78. for (int x=1;x<n+1;x++)
  79. {
  80.  
  81. for (int y=1;y<m+1;y++)
  82. {
  83.  
  84. if(matriz[x][y].equals("*"))
  85. {
  86.  
  87. matrizentera[x][y]=-1;
  88.  
  89. if ( !matriz[x][y+1].equals("*"))
  90. {
  91. matrizentera[x][y+1]++;
  92. }
  93. if ( !matriz[x][y-1].equals("*"))
  94. {
  95. matrizentera[x][y-1]++;
  96. }
  97. if ( !matriz[x-1][y].equals("*"))
  98. {
  99. matrizentera[x-1][y]++;
  100. }
  101. if ( !matriz[x+1][y].equals("*"))
  102. {
  103. matrizentera[x+1][y]++;
  104. }
  105. if ( !matriz[x-1][y+1].equals("*"))
  106. {
  107. matrizentera[x-1][y+1]++;
  108. }
  109. if ( !matriz[x-1][y-1].equals("*"))
  110. {
  111. matrizentera[x-1][y-1]++;
  112. }
  113. if ( !matriz[x+1][y+1].equals("*"))
  114. {
  115. matrizentera[x+1][y+1]++;
  116. }
  117. if ( !matriz[x+1][y-1].equals("*"))
  118. {
  119. matrizentera[x+1][y-1]++;
  120. }
  121.  
  122.  
  123. }
  124. }
  125. }
  126.  
  127.  
  128. for(int s=0;s<n+2;s++)
  129. {
  130. for (int j=0;j<m+2;j++)
  131. {
  132. if (matrizentera[s][j]==-1)
  133. {
  134. matrizre[s][j]="*";
  135. }else
  136. {
  137. matrizre[s][j]= Integer.toString(matrizentera[s][j]);
  138. }
  139.  
  140. }
  141.  
  142. }
  143.  
  144.  
  145. System.out.println("Field #"+con+":");
  146.  
  147. for(int s=1;s<n+1;s++)
  148. {
  149. for (int j=1;j<m+1;j++)
  150. {
  151. System.out.print(matrizre[s][j]);
  152.  
  153. } System.out.println("");
  154.  
  155. }
  156.  
  157. }
  158.  
  159.  
  160. }
  161.  
  162. }
  163.  
  164. }
Success #stdin #stdout 0.07s 380224KB
stdin
4 4
*...
....
.*..
....
3 5
**...
.....
.*...
0 0
stdout
Field #1:
1*10
1221
01*1
0111

Field #2:
1**10
13320
01*10