https://www.acmicpc.net/problem/5800
import java.util.Scanner;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int K = sc.nextInt(); // 반의 수
int ban = 1; // 몇 반?
while(ban <= K){
int student = sc.nextInt(); // 학생 수
int [] mathScore = new int [student]; // 수학 점수 배열
for(int i=0; i<student; i++) // 수학 점수 입력
mathScore[i] = sc.nextInt();
Arrays.sort(mathScore); // 내림차순으로 정렬
// 가장 큰 인접한 점수 차이 구하기
int maxSub = Math.abs(mathScore[0]-mathScore[1]);
for(int i=1; i<student-1; i++){
if(maxSub < Math.abs(mathScore[i]-mathScore[i+1]))
maxSub = Math.abs(mathScore[i]-mathScore[i+1]);
}
// 예제 처럼 출력
System.out.println("Class "+ ban);
System.out.println("Max "+mathScore[mathScore.length-1]
+", Min "+mathScore[0]+", Largest gap "+maxSub);
ban++; // 다음 class
}
}
}
'코딩테스트 > 백준' 카테고리의 다른 글
[백준-자바] 1120번 문자열 / 2022.05.09 (0) | 2022.05.09 |
---|---|
[백준-자바] 5671번 호텔 방 번호 / 2022.05.02 (0) | 2022.05.02 |
[백준-자바] 1292번 쉽게 푸는 문제 / 2022.04.27 (0) | 2022.04.27 |
[백준-자바] 1475번 방 번호 / 2022.04.01 (0) | 2022.04.01 |
[백준-자바] 1057번 토너먼트 / 2022.03.31 (0) | 2022.03.31 |