728x90
문제 링크: https://www.acmicpc.net/problem/5800
5800번: 성적 통계
첫째 줄에 중덕 고등학교에 있는 반의 수 K (1 ≤ K ≤ 100)가 주어진다. 다음 K개 줄에는 각 반의 학생수 N (2 ≤ N ≤ 50)과 각 학생의 수학 성적이 주어진다. 시험 성적은 0보다 크거나 같고, 100보다
www.acmicpc.net
문제 풀이
배열을 받은 후 정렬하여 최댓값과 최솟값을 구하고 반복문을 이용해서 가장 큰 점수 차이를 구하면 된다.
코드
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
int main() { | |
int k, n, st; | |
int MIN, MAX, ans; | |
vector<int> arr; | |
cin >> k; | |
for (int i = 1; i <= k; i++){ | |
cin >> n; | |
arr.clear(); | |
for (int j = 0; j < n; j++){ | |
cin >> st; | |
arr.push_back(st); | |
} | |
sort(arr.begin(), arr.end()); | |
MIN = arr[0]; | |
MAX = arr[arr.size()-1]; | |
ans = 0; | |
for (int j = 1; j < n; j++){ | |
ans = max(ans, arr[j]-arr[j-1]); | |
} | |
cout << "Class " << i << "\n" << "Max " << MAX << ", Min " << MIN << ", Largest gap " << ans << "\n"; | |
} | |
} |
728x90
'BOJ' 카테고리의 다른 글
[BOJ][Python] 백준 5612번 - 터널의 입구와 출구 (0) | 2022.03.31 |
---|---|
[BOJ][C++] 백준 11098번 - 첼시를 도와줘! (0) | 2022.03.31 |
[BOJ][C++] 백준 15719번 - 중복된 숫자 (0) | 2022.03.30 |
[BOJ][Python] 백준 1013번 - Contact (0) | 2022.03.30 |
[BOJ][Python] 백준 24513번 - 좀비 바이러스 (0) | 2022.03.30 |