01-25 03:45
Recent Posts
Recent Comments
Tags
- python
- Naver Cloud
- μ€ν½λ ν
- μλμ΄λ Έ
- μ΄λΈμ
- μλ°
- API MarketPlace κΈλ‘λ² μν¬ν°μ¦
- mysql
- νμ΄μ¬
- SQL
- ICT
- νλ‘λ³΄λ Έ
- APIλ§μΌνλ μ΄μ€
- RaspberryPi
- μ¨μΌλν
- TSQL
- μ€ν½μ€λΉ
- Java
- appetizer
- ICTλ©ν λ§
- DATABASE
- νμ΄μ곡λͺ¨μ
- νμ΄μ
- ict곡λͺ¨μ
- μ‘νκ³
- Spring
- JOBνκ³
- linux
- λ°μ΄ν°λ² μ΄μ€
- DB
- Today
- Total
miinsun
[Algorithm]μκ³ λ¦¬μ¦ μλ°_21 격μν μ΅λν© λ³Έλ¬Έ
π¬ λ¬Έμ μ€λͺ
5*5 격μνμ μλλ‘Έ κ°μ΄ μ«μκ° μ νμμ΅λλ€.
N*Nμ 격μνμ΄ μ£Όμ΄μ§λ©΄ κ° νμ ν©, κ° μ΄μ ν©, λ λκ°μ μ ν© μ€ κ° μ₯ ν° ν©μ μΆλ ₯ν©λλ€.
π¨ μ μΆλ ₯ μ
μ λ ₯ - 첫 μ€μ μμ°μ Nμ΄ μ£Όμ΄μ§λ€.(2<=N<=50)
λ λ²μ§Έ μ€λΆν° Nμ€μ κ±Έμ³ κ° μ€μ Nκ°μ μμ°μκ° μ£Όμ΄μ§λ€.
κ° μμ°μλ 100μ λμ§ μλλ€.
5
10 13 10 12 15
12 39 30 23 11
11 25 50 53 15
19 27 29 37 27
19 13 30 13 19
μΆλ ₯ - μ΅λν©μ μΆλ ₯ν©λλ€.
155
β
π» Solution.java
import java.util.Scanner;
public class Main {
public int solution(int[][] arr) {
int answer = Integer.MIN_VALUE;
int sum1, sum2;
for(int i = 0; i < arr.length; i++) {
sum1 = sum2 = 0;
for(int j = 0; j < arr.length; j++) {
sum1 += arr[i][j];
sum2 += arr[j][i];
}
answer = Math.max(answer, sum1);
answer = Math.max(answer, sum2);
}
sum1 = sum2 = 0;
for(int i = 0; i < arr.length; i++) {
sum1 += arr[i][i];
sum2 += arr[i][arr.length - i - 1];
}
answer = Math.max(answer, sum1);
answer = Math.max(answer, sum2);
return answer;
}
public static void main(String[] args){
Main main = new Main();
Scanner sc =new Scanner(System.in);
int n = sc.nextInt();
int[][] arr = new int[n][n];
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
arr[i][j] = sc.nextInt();
}
}
System.out.println(main.solution(arr));
sc.close();
return ;
}
}
'Algorithm > Java' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Algorithm]μκ³ λ¦¬μ¦ μλ°_23 λ©ν λ§ (0) | 2022.01.04 |
---|---|
[Algorithm]μκ³ λ¦¬μ¦ μλ°_22 λ΄μ°λ¦¬ (0) | 2022.01.03 |
[Algorithm]μκ³ λ¦¬μ¦ μλ°_20 λ±μ ꡬνκΈ° (0) | 2022.01.03 |
[Algorithm]μκ³ λ¦¬μ¦ μλ°_19 μ μ κ³μ° (0) | 2022.01.03 |
[Algorithm]μκ³ λ¦¬μ¦ μλ°_18 λ€μ§μ μμ (0) | 2022.01.03 |
Comments