https://www.acmicpc.net/problem/2587
2587번: 대표값2
어떤 수들이 있을 때, 그 수들을 대표하는 값으로 가장 흔하게 쓰이는 것은 평균이다. 평균은 주어진 모든 수의 합을 수의 개수로 나눈 것이다. 예를 들어 10, 40, 30, 60, 30의 평균은 (10 + 40 + 30 + 60 +
www.acmicpc.net
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <cmath>
#include <functional>
#include <string>
using namespace std;
void fastIO();
int main()
{
vector<int> vec;
int N, sum =0, mid;
for (auto i = 0; i < 5; i++)
{
cin >> N;
vec.push_back(N);
sum += N;
}
cout << sum / vec.size() <<endl;
sort(vec.begin(), vec.end());
cout << vec[vec.size() / 2] << endl;
}
void fastIO()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
'STUDY > Baekjoon' 카테고리의 다른 글
[백준] 2581 소수 c++ (0) | 2023.03.27 |
---|---|
[백준] 2798 c++ 블랙잭 (0) | 2022.08.25 |
[백준] 2869 c++ 달팽이는 올라가고 싶다 (0) | 2022.08.25 |
[백준] 1316 c++ 그룹 단어 체커 (0) | 2022.08.25 |
[백준] 25304 c++ 영수증 (0) | 2022.08.24 |