We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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);
}
});
Iterator <List<Integer>> itrarrs= arr.iterator();
Integer [][] matrix=new Integer[arr.size()][arr.size()];
int i=0;
int h=0;
while(itrarrs.hasNext()){
Iterator <Integer> itrnums=itrarrs.next().iterator();
while(itrnums.hasNext()){
matrix[i][h]=itrnums.next();
h++;
}
h=0;
i++;
}
int mayor=-99;
int acum=0;
int count=0;
while(count<16){
for(int l=0;l < 4;l++){
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 3; y++) {
acum+=matrix[l][y+x];
acum+=matrix[l+2][y+x];
}
acum+=matrix[l+1][x+1];
if(acum>=mayor){
mayor=acum;
}
acum=0;
count++;
}
count++;
}
}
System.out.println(mayor);
bufferedReader.close();
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 11: 2D Arrays
You are viewing a single comment's thread. Return to all comments →
public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
}