Notice
Recent Posts
문제 풀이 및 개발 공간
[백준] 5800번 성적 통계 문제! (silver 5 본문
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
int k=Integer.parseInt(br.readLine());
int[] score;
int max=0;
for(int i=0; i<k; i++) {
st=new StringTokenizer(br.readLine());
int n=Integer.parseInt(st.nextToken());
score=new int[n];
for(int j=0; j<n; j++) {
score[j]=Integer.parseInt(st.nextToken());
}
score=bubbleSort(score,score.length);
max=maxMinus(score);
bw.write("Class "+(i+1)+"\n");
bw.write("Max "+score[n-1]+", Min "+score[0]+", Largest gap "+max+"\n");
}
bw.flush();
}
public static int[] bubbleSort(int[] score, int length) {
int temp;
for(int i=length-1; i>0; i--) {
for(int j=0; j<i; j++) {
if(score[j]>score[j+1]) {
temp=score[j+1];
score[j+1]=score[j];
score[j]=temp;
}
}
}
return score;
}
public static int maxMinus(int[] score) {
int max=0;
for(int i=0; i<score.length-1; i++) {
if(score[i+1]-score[i]>max) {
max=score[i+1]-score[i];
}
}
return max;
}
}
'백준공부 > java' 카테고리의 다른 글
[백준] 1302번 베스트셀러 문제! (silver 4 (0) | 2022.08.18 |
---|---|
[백준] 21919번 소수 최소 공배수 문제! (silver 3 (0) | 2022.08.18 |
[백준] 9076번 점수 집계 문제! (bronze 2 (0) | 2022.08.18 |
[백준] 2693번 N번째 큰 수 문제! (bronze 1 (0) | 2022.08.17 |
[백준] 6219번 소수의 자격 문제! (silver 3 (0) | 2022.08.17 |