Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.math.*;
- /**
- * Auto-generated code below aims at helping you parse
- * the standard input according to the problem statement.
- **/
- class Solution {
- public static void main(String args[]) {
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- int m = in.nextInt();
- List<Integer> enemies = new ArrayList<>();
- char[][] mat = new char[m][m];
- if (in.hasNextLine()) {
- in.nextLine();
- }
- for (int i = 0; i < m; i++) {
- String battleground = in.nextLine();
- for(int j = 0; j < m; j++)
- mat[i][j] = battleground.charAt(j);
- }
- if(m <= n)
- System.out.println(numberOfX(mat,m));
- else
- {
- for(int i = 0; i <= m - n; i++)
- {
- for(int j = 0; j <= m - n; j++)
- enemies.add(numberEnemiesInSquare(mat,i,j,n));
- }
- int max = 0;
- for(int x : enemies)
- if(x > max)
- max = x;
- System.out.println(max);
- }
- }
- public static int numberEnemiesInSquare(char[][] mat,int x, int y, int size)
- {
- int enemies = 0;
- for(int i = x; i < x + size; i++)
- for(int j = y; j < y + size; j++)
- if(mat[i][j] == 'x')
- enemies++;
- return enemies;
- }
- public static int numberOfX(char[][] mat,int size)
- {
- /* plutôt
- return numberEnemiesInSquare(mat, 0, 0, size);
- */
- int total = 0;
- for(int i = 0; i < size; i++)
- for(int j = 0; j < size; j++)
- if(mat[i][j] == 'x')
- total++;
- return total;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement