그럴듯한 개발 블로그
Published 2023. 9. 17. 17:55
백준 18110 solved.ac c++ <algorithm>/백준
반응형

https://www.acmicpc.net/problem/18110

 

18110번: solved.ac

5명의 15%는 0.75명으로, 이를 반올림하면 1명이다. 따라서 solved.ac는 가장 높은 난이도 의견과 가장 낮은 난이도 의견을 하나씩 제외하고, {5, 5, 7}에 대한 평균으로 문제 난이도를 결정한다.

www.acmicpc.net

대충 부동소수점 연산 해보는 문제이다. devide by zero만 신경써주면 어렵지 않다.

#include <string>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stack>
#include <unordered_set>
#include <utility>
#include <cmath>
using namespace std;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	double n;
	cin >> n;
	vector<int> v;
	int exclude = static_cast<int>(round(n * 0.15));
	for (int i = 0; i < n; i++) {
		int input;
		cin >> input;
		v.push_back(input);
	}
	sort(v.begin(), v.end());
	double res = 0;
	int resCnt = n - (exclude * 2);
	if (resCnt == 0) {
		cout << 0;
		return 0;
	}
	for (int i = exclude; i < n - exclude; i++)
		res += v[i];
	cout << round(res / resCnt);
}
반응형

'<algorithm> > 백준' 카테고리의 다른 글

백준 1107 리모컨 c++  (0) 2023.09.17
백준 18111 마인크래프트 c++  (0) 2023.09.17
백준 1987 알파벳 c++  (0) 2023.09.16
백준 1931 회의실 배정 c++  (0) 2023.09.15
백준 9935 문자열 폭발 c++  (0) 2023.09.12
profile

그럴듯한 개발 블로그

@donghyk2

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!