각 클래스별 데이터를 정렬해서
max
와min
을 사용해서 가장 높은 점수와 가장 낮은 점수를 구하고 인접한 점수들의 차이를 구해서 점수 차이보다 큰 값을 가진다면 최댓값을 갱신해주는 방식으로 코드를 작성했다.
K = int(input())
Class = []
cnt = 1
for i in range(K):
Max_Gap = 0
information = list(map(int, input().split()))
information = sorted(information[1:])
Class.append(information)
max_score = max(Class[i])
min_score = min(Class[i])
for t in range(len(information) - 1):
if abs(information[t] - information[t + 1]) > Max_Gap:
Max_Gap = abs(information[t] - information[t + 1])
print("Class", cnt)
print("Max", str(max_score) + ",", "Min", str(min_score) + ",", "Largest gap", Max_Gap)
cnt += 1