티스토리 뷰

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

class Solution {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();

        int T = Integer.parseInt(br.readLine());
        for (int t = 1; t <= T; t++) {
            int n = Integer.parseInt(br.readLine());
            StringTokenizer st = new StringTokenizer(br.readLine());

            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < n * 2; i++) {
                list.add(Integer.parseInt(st.nextToken()));
            }

            Collections.sort(list, Collections.reverseOrder());

            List<Integer> result = new ArrayList<>();
            while (!list.isEmpty()) {
                int num = list.remove(0);
                int calculateNum = (int) (num * 0.75);
                result.add(calculateNum);

                int findCalculateNumIdx = list.indexOf(calculateNum);
                list.remove(findCalculateNumIdx);
            }

            Collections.sort(result);

            sb.append("#" + t + " ");
            result.forEach(num -> sb.append(num + " "));
            sb.append("\n");
        }

        System.out.println(sb);
    }
}
Total
Today
Yesterday
최근에 올라온 글
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30