📖 문제 링크
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV139KOaABgCFAYh
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
✅ 최종 코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = null;
int[] wall = new int[100];
int T = 10;
int max = 0;
int min = 101;
int max_index = 0;
int min_index = 0;
for(int t=1;t<=T;t++) {
int dump = Integer.parseInt(br.readLine());
st = new StringTokenizer(br.readLine());
for (int i = 0; i < wall.length; i++) {
wall[i] = Integer.parseInt(st.nextToken());
}
for (int d = 0; d <= dump; d++) {
max = 0;
min = 101;
max_index = -1;
min_index = -1;
for (int i = 0; i < wall.length; i++) {
if(wall[i] > max) {
max = wall[i];
max_index = i;
}
if (wall[i] < min){
min = wall[i];
min_index = i;
}
}
if(d == dump)break;
wall[max_index] -= 1;
wall[min_index] += 1;
}
System.out.printf("#%d %d", t, wall[max_index] - wall[min_index]);
System.out.println();
}
}//main
}
'알고리즘 > Java' 카테고리의 다른 글
[백준/JAVA] 16935번 : 배열돌리기3 (0) | 2022.08.14 |
---|---|
[백준/JAVA] 16926번 : 배열 돌리기1 (0) | 2022.08.14 |
[백준/JAVA] 2751번 : 수정렬하기2 (0) | 2022.08.12 |
[백준/JAVA] 10815번 : 숫자카드 (0) | 2022.08.12 |
[SWEA/JAVA] 1861번 : 정사각형방 (0) | 2022.08.09 |