티스토리 뷰
https://www.acmicpc.net/problem/2108
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
int N;
cin >> N;
int sum = 0, max, cnt=0;;
int arr[N]; //입력받는 수
int bindo[8001] = {0, }; //최빈값을 구하기 위한 배열
bool not_first = false; //같은 값이 나오는 지 확인하기 위한 bool형 변수
for(int i=0; i<N; i++)
{
cin >> arr[i];
sum += arr[i];
bindo[arr[i]+4000]++;
}
sort(arr, arr+N); //오름차순 정렬
for(int i=0; i<8001; i++)
{
if(bindo[i] == cnt)
{
if(not_first)
{
max = i-4000;
not_first = false;
}
}
if(bindo[i] > cnt)
{
max = i-4000;
cnt = bindo[i];
not_first = true; //나온 횟수
}
}
cout << round((double)sum / N) << '\n'; //산술평균
cout << arr[N/2] << '\n'; //중앙값
cout << max << '\n'; //최빈값
cout << arr[N-1]-arr[0] << '\n'; //범위
return 0;
}
'PS > BOJ C++' 카테고리의 다른 글
18870번 - 좌표 압축 (0) | 2021.10.16 |
---|---|
9507번 - Generations of Tribbles (0) | 2021.10.13 |
11653번 - 소인수분해 (0) | 2021.10.06 |
1059번 - 좋은 구간 (0) | 2021.10.03 |
3036번 - 링 (0) | 2021.09.26 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 수학
- 러스트
- 17478
- 10845
- 백준
- 1715
- 프로그래머스
- 1764
- 싸피
- 10815
- 덱
- 딕셔너리
- 조합
- 백트래킹
- 1759
- dp
- 자료구조
- 2805
- 11051
- 빌림
- heapq
- 1182
- 삼성청년소프트웨어아카데미
- 브루트포스
- 10971
- 1358
- 큐
- 10816
- 스택
- 파이썬
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함