온라인 저지/백준
[백준] 13771 - Presents
rrrmaster
2021. 8. 1. 12:33
문제 링크
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번째 자리까지 출력을 해야 된다.