Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package practice2017;
- import java.util.Scanner;
- public class Corcaighxit {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt() + 2, m = sc.nextInt() + 2;
- char[][] map = new char[n][m];
- // Fill the array and pad with o's
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- if ((i == 0) || (j == 0) || (i == n-1) || (j == m-1)) {
- map[i][j] = 'o';
- } else {
- map[i][j] = sc.next().charAt(0);
- }
- }
- }
- // Check the array
- for(int i = 1; i < n-1; i++) {
- for(int j = 1; j < m-1; j++) {
- int count = 0;
- if(map[i][j] == 'o') {
- if(map[i-1][j-1] == 'x')
- count++;
- if(map[i-1][j] == 'x')
- count++;
- if(map[i-1][j+1] == 'x')
- count++;
- if(map[i][j-1] == 'x')
- count++;
- if(map[i][j+1] == 'x')
- count++;
- if(map[i+1][j-1] == 'x')
- count++;
- if(map[i+1][j] == 'x')
- count++;
- if(map[i+1][j+1] == 'x')
- count++;
- map[i][j] = Integer.toString(count).charAt(0);
- }
- }
- }
- // Print the array
- for(int i = 1; i < n-1; i++) {
- for(int j = 1; j < m-1; j++) {
- System.out.print(map[i][j] + " ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement