Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Minesweeper {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int fieldCount = 1;
- while(sc.hasNext()){
- String[] info = sc.nextLine().trim().split(" ");
- int rows = Integer.parseInt(info[0]);
- int coloums = Integer.parseInt(info[1]);
- if(rows == 0 && coloums == 0){
- break;
- }
- char[][] array = new char[rows][coloums];
- for(int r=0; r<rows; r++){
- String foo = sc.nextLine().trim().replace('.', '0');
- for(int c=0; c<coloums; c++){
- array[r][c] = foo.charAt(c);
- }
- }
- for(int r=0; r<rows; r++){
- for(int c=0; c<coloums; c++){
- if(array[r][c] == '*'){
- int rStart = r-1;
- if(r == 0){
- rStart++;
- }
- int rDone = r+1;
- if(r == rows-1){
- rDone--;
- }
- int cStart = c-1;
- if(c == 0){
- cStart++;
- }
- int cDone = c+1;
- if(c == coloums-1){
- cDone--;
- }
- for(int i=rStart; i<=rDone; i++){
- for(int k=cStart; k<=cDone; k++){
- if(array[i][k] != '*'){
- int temp = array[i][k] -'0';
- temp++;
- array[i][k] = (char) (temp+'0');
- }
- }
- }
- }
- }
- }
- System.out.println("Field #" + fieldCount + ":");
- for(int r=0; r<rows; r++){
- String foo = "";
- for(int c=0; c<coloums; c++){
- foo += array[r][c];
- }
- System.out.println(foo);
- }
- fieldCount++;
- System.out.println();
- }
- sc.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement