<Algorithm> 110. 재관이의대량할인(SWExpert)
by BFine반응형
1. 재관이의대량할인(SWExpert)
간단한 정렬문제
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.LinkedList; import java.util.List; import java.util.StringTokenizer; import java.util.stream.IntStream; public class Solution { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); List<Integer> list = new LinkedList<>(); StringBuilder sb = new StringBuilder(""); /****************************** * 3개씩 묶었을때 큰값이면 되므로 * sort해서 3개씩 묶어서 * 처리하면 된다. *******************************/ for(int t = 0; t < T; t++) { int N = Integer.parseInt(br.readLine()); StringTokenizer st = new StringTokenizer(br.readLine()); IntStream.range(0, N).forEach(i->list.add(Integer.parseInt(st.nextToken()))); Collections.sort(list,Comparator.reverseOrder()); int cnt = 1; int total = 0; for(Integer in : list) { if(cnt == 3) {cnt=1;continue;} total+=in; cnt ++; } sb.append("#"+(t+1)+" "+total +"\n"); list.clear(); } System.out.println(sb.toString()); } } | cs |
참고 & 출처
반응형
'공부(2018~2019) - 스킨변경전 > Algorithm' 카테고리의 다른 글
<Algorithm> 112. 프로세서(SWExpert) (0) | 2019.02.15 |
---|---|
<Algorithm> 111. 3055번 탈출 (0) | 2019.02.13 |
<Algorithm> 109. 3190번 뱀 (0) | 2019.02.10 |
<Algorithm> 108. 전화번호목록(프로그래머스) (0) | 2019.02.09 |
<Algorithm> 107. 예산(프로그래머스) (1) | 2019.02.09 |
블로그의 정보
57개월 BackEnd
BFine