LardaX

Crossfire

Feb 18th, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. public class Crossfire {
  8.     public static void main(String[] args) throws IOException {
  9.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  10.         String[] dimensions = reader.readLine().split(" ");
  11.         int rows = Integer.parseInt(dimensions[0]);
  12.         int cols = Integer.parseInt(dimensions[1]);
  13.  
  14.         long token = 1;
  15.         List<List<Long>> matrix = new ArrayList<>();
  16.  
  17.         for (int i = 0; i < rows; i++) {
  18.             matrix.add(new ArrayList<>());
  19.             for (int j = 0; j < cols; j++) {
  20.                 matrix.get(i).add(token);
  21.                 token++;
  22.             }
  23.         }
  24.  
  25.         String command;
  26.         while (!"Nuke it from orbit".equals(command = reader.readLine())) {
  27.             String[] commandArgs = command.split(" ");
  28.             long row = Long.parseLong(commandArgs[0]);
  29.             long col = Long.parseLong(commandArgs[1]);
  30.             long radius = Integer.parseInt(commandArgs[2]);
  31.             long maxRow = row + radius > 200 ? 200 : row + radius;
  32.             long minRow = row - radius < 0? 0 : row - radius;
  33.             long maxCol = col + radius > 200 ? 200 : col + radius;
  34.             long minCol = col - radius < 0 ? 0 : col - radius;
  35.  
  36.             for (long currentRow = maxRow; currentRow >= minRow; currentRow--) {
  37.                 if (currentRow == row) {
  38.                     continue;
  39.                 }
  40.                 try {
  41.                     matrix.get((int) currentRow).remove((int)col);
  42.                 } catch (IndexOutOfBoundsException e){}
  43.             }
  44.  
  45.             for (long currentCol = maxCol; currentCol >= minCol; currentCol--) {
  46.                 try {
  47.                     matrix.get((int) row).remove((int)currentCol);
  48.                 } catch (IndexOutOfBoundsException e){}
  49.             }
  50.         }
  51.         StringBuilder sb = new StringBuilder();
  52.  
  53.         for (int row = 0; row < matrix.size(); row++) {
  54.             for (int col = 0; col < matrix.get(row).size(); col++) {
  55.                sb.append(matrix.get(row).get(col) + " ");
  56.             }
  57.             sb.append("\r\n");
  58.         }
  59.  
  60.         System.out.println(sb);
  61.     }
  62. }
Add Comment
Please, Sign In to add comment