SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=10;
for(int test_case = 1; test_case <= T; test_case++)
{
int dump = sc.nextInt();
int[] height = new int[100];
for(int i=0; i<100; i++){
height[i] = sc.nextInt();
}
for(int j=0; j<dump; j++){
int max =0;
int min =101;
int maxIndex = -1;
int minIndex = 101;
for(int k=0; k<100; k++){
if(height[k] >= max){
max = height[k];
maxIndex = k;
}
if(height[k]<=min){
min = height[k];
minIndex = k;
}
}
height[maxIndex] = height[maxIndex] -1;
height[minIndex] = height[minIndex] +1;
}
int lastMax = 0;
int lastMin = 101;
for(int l=0; l<100; l++){
if(lastMax <= height[l])
lastMax = height[l];
if(lastMin >= height[l])
lastMin = height[l];
}
System.out.println("#" + test_case + " " + (lastMax-lastMin));
}
}
}
단순하다. 최대최소 찾기 반복, 차이 경감, 다시 마지막으로 찾아서 차이 출력하기
'SWEA' 카테고리의 다른 글
[SWEA] 햄버거 다이어트 (0) | 2024.11.17 |
---|---|
[SWEA] Sum (0) | 2024.11.16 |
[SWEA] [S/W 문제해결 기본] 1일차 - View (2) | 2024.11.15 |
[SWEA] 등차수열 만들기 (1) | 2024.11.05 |
[SWEA] 식료품 가게 (0) | 2024.10.29 |