Notice
Recent Posts
Link
- Today
- Total
hye-log
[SWEA]1208번 Flatten(JAVA) 본문
0. 문제 링크
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV139KOaABgCFAYh
1. 문제 설명
1) 최고점과 최저점의 간격 줄이는 평탄화 진행하기
2. 입출력
// input
834
42 68 35 1 70 25 79 59 63 65 6 46 82 28 62 92 96 43 28 37 92 5 3 54 93 83 22 17 19 96 ...
// output
#1 13
3. 코드
import java.util.*;
public class swea1208 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = 10; // 테스트 케이스의 개수
for(int t = 1; t <= T; t++) {
int dump = sc.nextInt(); // 덤프 횟수
int[] boxes = new int[100]; // 상자들
for(int i = 0; i < 100; i++) {
boxes[i] = sc.nextInt();
}
for(int d = 0; d < dump; d++) {
Arrays.sort(boxes); // 정렬
boxes[0]++; // 최소값 증가
boxes[99]--; // 최대값 감소
}
Arrays.sort(boxes); // 정렬
System.out.printf("#%d %d\n", t, boxes[99]-boxes[0]);
}
}
}
실행 결과
4. 회고
1) 배열 정렬을 통해 최대값과 최소값을 구할 수 있음
5. Github
https://github.com/iihye/Algorithm/blob/main/SWEA/swea1208.java
728x90
'CodingTest > SWEA' 카테고리의 다른 글
[SWEA]1940번 가랏! RC카!(JAVA) (0) | 2023.07.30 |
---|---|
[SWEA]1974번 스도쿠 검증(JAVA) (0) | 2023.07.30 |
[SWEA]1234번 비밀번호(JAVA) (0) | 2023.07.29 |
[SWEA]2805번 농작물 수확하기(JAVA) (0) | 2023.07.29 |
[SWEA]7272번 안경이 없어!(JAVA) (0) | 2023.07.29 |
Comments