본문 바로가기

■ 알고리즘 문제 풀이/SWEA

[SWEA-D3] 1208. Flatten

▶문제설명

[SWEA] 1208. Flatten

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



▶Solution


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
import java.util.*;
 
class Solution{
    public static int[] BoxArr = new int[100];
    public static int DumpNum = 0;
    public static int val = -1;
    
     public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        for(int T = 1 ; T<=10 ; T++){
            DumpNum = sc.nextInt();
            for(int i = 0 ; i<100 ; i++){
                BoxArr[i] = sc.nextInt();
            }
            
            for(int i = 0 ; i<DumpNum ; i++){
                Arrays.sort(BoxArr);
                val = BoxArr[BoxArr.length-1- BoxArr[0];
                if( val == 0 || val == 1 ) 
                    break;
                
                BoxArr[BoxArr.length-1-= 1;
                BoxArr[0+= 1;
            }
            Arrays.sort(BoxArr);
            val = BoxArr[BoxArr.length-1- BoxArr[0];
            
            System.out.printf("#%d %d\n", T, val);
        }
    }
}
cs



'■ 알고리즘 문제 풀이 > SWEA' 카테고리의 다른 글

[SWEA-D4] 1211. Ladder2  (0) 2019.02.20
[SWEA-D4] 1210. Ladder1  (0) 2019.02.20
[SWEA-D3] 1209. Sum  (0) 2019.02.20
[SWEA-D3] 1206. View  (0) 2019.02.20
[SWEA-D2] 1204. 최빈수 구하기  (0) 2019.02.20