daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest May 17th, 2018 125 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package p13_blur_filter;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.ArrayList;
  7. import java.util.Arrays;
  8. import java.util.List;
  9.  
  10. public class Main {
  11.     public static void main(String[] args) throws IOException {
  12.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  13.         int blurAmount = Integer.parseInt(reader.readLine());
  14.         String[] matrixSize = reader.readLine().split("\\s+");
  15.         Long[][] matrix = new Long[Integer.parseInt(matrixSize[0])][Integer.parseInt(matrixSize[1])];
  16.  
  17.         for (int i = 0; i < matrix.length; i++) {
  18.             String[] temp = reader.readLine().split("\\s+");
  19.             for (int j = 0; j < matrix[i].length; j++) {
  20.                 matrix[i][j] = Long.parseLong(temp[j]);
  21.  
  22.             }
  23.         }
  24.  
  25.         int[] blurCoordinates = Arrays.stream(reader.readLine().split("\\s+")).mapToInt(Integer::parseInt).toArray();
  26.         int blurStartRow = blurCoordinates[0] - 1 < 0 ? blurCoordinates[0] : blurCoordinates[0] - 1;
  27.         int blurStartCol = blurCoordinates[1] - 1 < 0 ? blurCoordinates[1] : blurCoordinates[1] - 1;
  28.         int blurEndRow = blurCoordinates[0] + 1 >= matrix.length ? blurCoordinates[0] : blurCoordinates[0] + 1;
  29.         int blurEndCol = blurCoordinates[1] + 1 >= matrix[blurCoordinates[1]].length ? blurCoordinates[1] : blurCoordinates[1] + 1;
  30.  
  31.  
  32.         for (int i = blurStartRow; i <= blurEndRow; i++) {
  33.             for (int j = blurStartCol; j <= blurEndCol; j++) {
  34.                 matrix[i][j] += blurAmount;
  35.  
  36.             }
  37.         }
  38.  
  39.         print(matrix);
  40.     }
  41.  
  42.     private static void print(Long[][] matrix) {
  43.         for (Long[] lines : matrix) {
  44.             List<String> line = new ArrayList<>();
  45.             for (long number : lines) {
  46.                 line.add(String.valueOf(number));
  47.             }
  48.             System.out.println(String.join(" ", line));
  49.            
  50.         }
  51.     }
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top