Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. package practice2017;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Corcaighxit {
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.         int n = sc.nextInt() + 2, m = sc.nextInt() + 2;
  9.         char[][] map = new char[n][m];
  10.        
  11.         // Fill the array and pad with o's
  12.         for(int i = 0; i < n; i++) {
  13.             for(int j = 0; j < m; j++) {
  14.                 if ((i == 0) || (j == 0) || (i == n-1) || (j == m-1)) {
  15.                     map[i][j] = 'o';
  16.                 } else {
  17.                     map[i][j] = sc.next().charAt(0);
  18.                 }
  19.             }
  20.         }
  21.        
  22.         // Check the array
  23.         for(int i = 1; i < n-1; i++) {
  24.             for(int j = 1; j < m-1; j++) {
  25.                 int count = 0;
  26.                
  27.                 if(map[i][j] == 'o') {
  28.                     if(map[i-1][j-1] == 'x')
  29.                         count++;
  30.                     if(map[i-1][j] == 'x')
  31.                         count++;
  32.                     if(map[i-1][j+1] == 'x')
  33.                         count++;
  34.                     if(map[i][j-1] == 'x')
  35.                         count++;
  36.                     if(map[i][j+1] == 'x')
  37.                         count++;
  38.                     if(map[i+1][j-1] == 'x')
  39.                         count++;
  40.                     if(map[i+1][j] == 'x')
  41.                         count++;
  42.                     if(map[i+1][j+1] == 'x')
  43.                         count++;
  44.                    
  45.                     map[i][j] = Integer.toString(count).charAt(0);
  46.                 }
  47.             }
  48.         }
  49.        
  50.         // Print the array
  51.         for(int i = 1; i < n-1; i++) {
  52.             for(int j = 1; j < m-1; j++) {
  53.                 System.out.print(map[i][j] + " ");
  54.             }
  55.             System.out.println();
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement