반응형

[광고 누르면 오늘의 행운 상승!!]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWIseXoKEUcDFAWN&categoryId=AWIseXoKEUcDFAWN&categoryType=CODE

 

SW Expert Academy

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

swexpertacademy.com

D4인데 너무 쉽다

정렬해버리고 3번째 요소만 제하고 더한다. 

끝.

package Study5;

import java.io.*;
import java.util.*;

public class 재관이의대량할인 {

	static int T,N,ans;
	public static void main(String[] args) throws Exception {
		System.setIn(new FileInputStream("test.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		T = Integer.parseInt(st.nextToken());
		
		for (int tc = 1; tc <= T; tc++) {
			List<Integer> list = new ArrayList<>();
			int N = Integer.parseInt(br.readLine());
			st = new StringTokenizer(br.readLine());
			for (int i = 0; i < N; i++) {
				list.add(Integer.parseInt(st.nextToken()));
			}
			Collections.sort(list, Collections.reverseOrder());
			int sum = 0;
			int cnt = 1;
			for (int i = 0; i < list.size(); i++) {
				if(cnt % 2 == 0) continue; 
				sum += list.get(i);
				cnt++;
			}
			System.out.println("#" + tc + " " +sum);
		}
	}
}
반응형

+ Recent posts