You are viewing a single comment's thread. Return to all comments →
import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); List<List<Integer>> arr = new ArrayList<>(); IntStream.range(0, 6).forEach(i -> { try { arr.add( Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) .map(Integer::parseInt) .collect(toList()) ); } catch (IOException ex) { throw new RuntimeException(ex); } }); bufferedReader.close(); int largestHourglassValue = Integer.MIN_VALUE; for (int i=0; i < 4; i++) { for (int j=0; j < 4; j++) { int sum = arr.get(i).subList(j, j+3) .stream().mapToInt(Integer::intValue).sum(); sum += arr.get(i+1).get(j+1); sum += arr.get(i+2).subList(j, j+3) .stream().mapToInt(Integer::intValue).sum(); if (sum > largestHourglassValue) { largestHourglassValue = sum; } } } System.out.print(largestHourglassValue); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Java 2D Array
You are viewing a single comment's thread. Return to all comments →