๊ธฐ์ตํ ๊ฒ: ์ค๋ฆ์ฐจ์ ์ ๋ ฌ ํจ์ sort
ํค๋: #include<algorithm>
์ฌ์ฉ: sort(arr,arr+๋ฐฐ์ด ์์ ๊ฐฏ์)
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
for (int i = 1; i <= T; i++) {
int arr[199];
int N;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
sort(arr, arr + N);
int mid = N / 2;
cout << arr[mid] << "\n";
}
}
๊ตฌํ ๋ฌธ์ ์ ํ์ด๋ค.
#include<iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
for (int i = 1; i <= T; i++) {
int idx=0;
int countArr[101] = { 0 };
int testCaseNum;
cin >> testCaseNum;
int max = -1;
for (int j = 0; j <1000; j++) {
int score;
cin >> score;
countArr[score]++;
}
for (int k = 0; k < 101; k++) {
if (countArr[i] >= max) {
max = countArr[k];
idx = k;
}
}
cout << "#" << testCaseNum<< " " << idx << "\n";
}