Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- public class JediGalaxy {
- public static int[][] galaxy;
- public static int playerRow;
- public static int playerCol;
- public static int evilRow;
- public static int evilCol;
- public static long result = 0;
- public static void main(String[] args){
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));) {
- String[] dimensions = reader.readLine().trim().split("\\s+");
- int matrixRow = Integer.parseInt(dimensions[0]);
- int matrixCol = Integer.parseInt(dimensions[1]);
- galaxy = new int[matrixRow][matrixCol];
- fillMatrix(galaxy);
- String readerLine = reader.readLine();
- while (!readerLine.equals("Let the Force be with you")) {
- String[] splitLine = readerLine.trim().split("\\s+");
- playerRow = Integer.parseInt(splitLine[0]);
- playerCol = Integer.parseInt(splitLine[1]);
- readerLine = reader.readLine();
- splitLine = readerLine.trim().split("\\s+");
- evilRow = Integer.parseInt(splitLine[0]);
- evilCol = Integer.parseInt(splitLine[1]);
- getPoints();
- readerLine = reader.readLine();
- }
- System.out.println(result);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private static void getPoints() {
- for (int row = evilRow,col = evilCol; row >= 0; row--,col--) {
- if (isInside(galaxy,row,col)) {
- galaxy[row][col] = 0;
- }
- }
- for (int row = playerRow,col = playerCol; row >= 0 ; row--,col++) {
- if (isInside(galaxy,row,col)) {
- result += galaxy[row][col];
- }
- }
- }
- private static boolean isInside(int[][] matrix, int row, int col) {
- return row >= 0 && row < matrix.length && col >= 0 && col < matrix[row].length;
- }
- private static void fillMatrix(int[][] matrix) {
- int index = 0;
- for (int row = 0; row < matrix.length; row++) {
- for (int col = 0; col < matrix[row].length; col++) {
- matrix[row][col] = index++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment