Deep_Dev

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWZ2IErKCwUDFAUQ 

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

 


3๊ฐœ ํ•ฉ์„ ๊ตฌํ•  ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ HashSet์— ๋„ฃ์–ด์„œ ์ค‘๋ณต์„ ์ œ๊ฑฐํ•˜๊ณ 

 

Set์˜ ๊ฐ’๋“ค์„ ArrayList์— ๋„ฃ์–ด ์ •๋ ฌํ•˜์—ฌ, ๋์—์„œ 5๋ฒˆ์งธ ๊ฐ’์„ ์ถ”์ถœํ•œ๋‹ค.

 

 

 

 

 

import java.util.*;
class Solution{
	public static void main(String args[]) throws Exception{
	     Scanner kb = new Scanner(System.in);
        int t = kb.nextInt();
        for (int test_case = 1; test_case <= t; test_case++) {
            int[] arr = new int[7];
            for (int i = 0; i < 7; i++) arr[i] = kb.nextInt();

            Set<Integer> set = new HashSet<Integer>();
            for (int i = 0; i < 5; i++) {
                for (int j = i + 1; j < 6; j++) {
                    for (int k = j + 1; k < 7; k++) {
                        set.add(arr[i] + arr[j] + arr[k]);
                    }
                }
            }
            ArrayList<Integer> list = new ArrayList<>(set);
            Collections.sort(list);
            System.out.println("#" + test_case + " " + list.get(list.size() - 5));
        }
    }
}