"HR자바 Java 2D Array"의 두 판 사이의 차이

(새 문서: ==개요== ;{{subst:PAGENAME}} * {{HR자바 헤더}} {{HR자바 Data Structures}} |} ---- <source lang='java'> </source> <source lang='java'> </source> <source lang='java'> </source>)
 
잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(다른 사용자 한 명의 중간 판 3개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;HR자바 Java 2D Array
;HR자바 Java 2D Array
*  
* https://www.hackerrank.com/challenges/java-2d-array/problem
* 참고: [[HR30 Day 11: 2D Arrays]]


{{HR자바 헤더}}
{{HR자바 헤더}}
9번째 줄: 10번째 줄:
----
----


<source lang='java'>
<syntaxhighlight lang='java'>
</source>
import java.io.*;
<source lang='java'>
import java.math.*;
</source>
import java.security.*;
<source lang='java'>
import java.text.*;
</source>
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
 
public class Solution {
    private static final Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {
        int[][] arr = new int[6][6];
        for (int i = 0; i < 6; i++) {
            String[] arrRowItems = scanner.nextLine().split(" ");
            scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
            for (int j = 0; j < 6; j++) {
                int arrItem = Integer.parseInt(arrRowItems[j]);
                arr[i][j] = arrItem;
            }
        }
        scanner.close();
       
        int sum;
        int max = -100;
        for(int i=1; i<5; i++) {
            for(int j=1; j<5; j++) {
                sum = arr[i-1][j-1] + arr[i-1][j] + arr[i-1][j+1]
                    + arr[i][j]
                    + arr[i+1][j-1] + arr[i+1][j] + arr[i+1][j+1];
                if( sum > max ) max = sum;
            }
        }
        System.out.println( max );
    }
}
</syntaxhighlight>

2020년 11월 2일 (월) 02:51 기준 최신판

개요[ | ]

HR자바 Java 2D Array
해커랭크 Java
# 문제 비고
HR자바 Data Structures e
28 HR자바 Java 1D Array
29 HR자바 Java 2D Array
30 HR자바 Java Subarray
31 HR자바 Java Arraylist
32 HR자바 Java 1D Array (Part 2)
33 HR자바 Java List
34 HR자바 Java Map
35 HR자바 Java Stack
36 HR자바 Java Hashset
37 HR자바 Java Generics
38 HR자바 Java Comparator
39 HR자바 Java Sort
40 HR자바 Java Dequeue
41 HR자바 Java BitSet
42 HR자바 Java Priority Queue

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Solution {
    private static final Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {
        int[][] arr = new int[6][6];
        for (int i = 0; i < 6; i++) {
            String[] arrRowItems = scanner.nextLine().split(" ");
            scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
            for (int j = 0; j < 6; j++) {
                int arrItem = Integer.parseInt(arrRowItems[j]);
                arr[i][j] = arrItem;
            }
        }
        scanner.close();
        
        int sum;
        int max = -100;
        for(int i=1; i<5; i++) {
            for(int j=1; j<5; j++) {
                sum = arr[i-1][j-1] + arr[i-1][j] + arr[i-1][j+1]
                    + arr[i][j]
                    + arr[i+1][j-1] + arr[i+1][j] + arr[i+1][j+1];
                if( sum > max ) max = sum;
            }
        }
        System.out.println( max );
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}