Algorithm

[SWEA] 4050. 재관이의 대량 할인

프로그래민 2020. 4. 30. 00:02
반응형

단순 구현 문제이다.

단순 구현 문제이긴 하지만 과정을 좀 생각해야했던 문제이다. 내림차순으로 정렬후 3개씩 묶고 그중 가작 작은걸 빼주는 식으로 구현하였다.

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
47
48
49
50
package swea;
 
 
public class Solution_d4_4050_재관이의대량할인 {
    
    static int[] arr;
    static int discount;
    
    
    public static void main(String[] args) throws Exception {
        BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = null;
        
        int T=Integer.parseInt(br.readLine());
        for(int tc=1;tc<=T;tc++) {
            int num=Integer.parseInt(br.readLine());
            
            discount=num/3;
            
            arr=new int[num];
            st=new StringTokenizer(br.readLine());
            int index=0;
            while(st.hasMoreTokens())
                arr[index++]=Integer.parseInt(st.nextToken());
            
            Arrays.sort(arr);
            
            index=num-1;
            while(discount!=0) {
                arr[index-2]=0;
                index-=3;
                discount-=1;
            }
            
            
            
            int answer=0;
            for(int i=0;i<num;i++)
                answer+=arr[i];
            
            System.out.println("#"+tc+" "+answer);
        }
        
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
                                             
반응형

'Algorithm' 카테고리의 다른 글

[BOJ] 12100. 2048(Easy)  (0) 2020.04.30
[SWEA] 6019. 추억의 2048게임  (0) 2020.04.30
[SWEA] 5658. 보물상자 비밀번호  (0) 2020.04.29
[Programmers] 불량 사용자  (0) 2020.04.28
[Programmers] 튜플  (0) 2020.04.27