프로그래밍/알고리즘

no.18110 solved.ac

데일리 백수 2025. 1. 6. 19:10
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int calc_result(int N) {
	double result = 0;
	result = N * (15.0 / 100.0);
	return floor(result + 0.5);

}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    vector<int> scores;
    int N, M = 0;
    double result = 0;
    cin >> N;
    if (N == 0) {
        cout << 0;
    }
    else {
        for (int i = 0; i < N; i++) {
            int temp = 0;
            cin >> temp;
            scores.push_back(temp);
        }
        M = calc_result(N);
        sort(scores.begin(), scores.end());

        for (int i = M; i < N - M; i++) {
            result += scores[i];
        }

        result = result / (N - (M * 2));

        cout << floor(result + 0.5) << endl;
    }

  

}

문제 분석

간단한 문제이다. 기본 올림,반올림등의 함수를 사용할 수 있는지가 문제의 난도를 크게 가르는것같다.

std::round 를사용해도 되지만 , 0.5를 더한다음 floor를 사용하는 방식으로 반올림을 해결하였다.

 

문제를 푸는 과정은 

1.N개의 리뷰를 받을지 입력

2.N개의 15퍼센트를 구해준 후, 반올림 

3.15퍼센트만 큼 배제한 후, 계산을 진행해준다.

 

간단한 문제이다.

'프로그래밍 > 알고리즘' 카테고리의 다른 글

no.1253 좋다  (0) 2025.01.08
no.18111 마인크래프트  (0) 2025.01.07
no.1764 듣보잡  (1) 2025.01.05
no.1012 유기농 배추  (0) 2025.01.04
no.2606 바이러스  (0) 2025.01.03