๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/12941?language=java
ํ์ด
import java.util.*;
public class ์ต์๊ฐ๋ง๋ค๊ธฐ {
public static void main(String[] args) {
int []A = {1,4,2};
int []B = {5,4,4};
int answer = 0;
Arrays.sort(A);
Arrays.sort(B);
for(int i=0; i<A.length; i++){
answer += A[i]*B[A.length - 1 - i];
}
System.out.println(answer);
}
}
์ต์๊ฐ์ ๋ง๋ค๊ธฐ ์ํด ๊ฐ์ฅ ์์๊ฐ * ๊ฐ์ฅ ํฐ ๊ฐ์ ํด์ผํ๋ค. ๊ทธ๋ฌ๊ธฐ ์ํด ๋ฐฐ์ด A๋ ์ค๋ฆ์ฐจ์ ์ ๋ ฌํ๊ณ B๋ ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ ํ ์์ฐจ์ ์ผ๋ก ๊ณฑํด์ฃผ๋ฉด ์ต์๊ฐ์ ๊ตฌํ ์ ์๋ค.
'๐๏ธ Algorithm > โฌ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
โฌ [Programmers] [Java] [Level2] ์ง์ง์ด ์ ๊ฑฐํ๊ธฐ (0) | 2024.01.07 |
---|---|
โฌ [Programmers] [Java] [Level2] ์ด์ง ๋ณํ ๋ฐ๋ณตํ๊ธฐ (1) | 2024.01.04 |
โฌ [Programmers] [Java] [Level2] JadenCase ๋ฌธ์์ด ๋ง๋ค๊ธฐ (1) | 2023.12.23 |
โฌ [Programmers] [Java] [Level2] ์ต๋๊ฐ๊ณผ ์ต์๊ฐ (0) | 2023.12.14 |
โฌ [Programmers] [Java] [Level1] ์๋ฆฟ์ ๋ํ๊ธฐ (0) | 2023.12.11 |