소소한 개발자
[백준] 13771 - Presents 본문
문제 링크
13771번: Presents (acmicpc.net)
13771번: Presents
Input will consist of a single scenario which contains a list of prices from a shop, each on a separate line. The first line will contain N, the number of prices (2 <= N <= 100). No price will be duplicated. The next N lines will each contain a single pric
www.acmicpc.net
코드
#include <iostream>
#include <algorithm>
int main()
{
int n;
float a[101];
std::cin >> n;
for (int i = 0; i < n; i++)
std::cin >> a[i];
std::sort(a, a + n);
std::cout.precision(2);
std::cout << std::fixed << a[1];
}
풀이 해설
이 문제는 2번째로 가격이 낮은 선물을 고르는 문제이다.
고로 오름차순 정렬을 진행한 후 1번째 인덱스를 조회하면 된다.
이 문제에서 주의해야 될 점은 소수점을 무조건 2번째 자리까지 출력을 해야 된다.
'온라인 저지 > 백준' 카테고리의 다른 글
[백준] 14726 - 신용카드 판별 (0) | 2021.08.06 |
---|---|
[백준] 1388 - 바닥 장식 (0) | 2021.08.05 |
[백준] 14730 - 謎紛芥索紀 (Small) (0) | 2021.08.05 |
[백준] 2959 - 거북이 (0) | 2021.08.01 |
[백준] 17608 - 막대기 (0) | 2021.08.01 |
Comments