Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
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
31
Archives
Today
Total
관리 메뉴

코딩로그

[백준/BOJ/C++] 13771번 Presents 본문

YJ/C++

[백준/BOJ/C++] 13771번 Presents

Team DAON 2021. 11. 2. 17:32

[문제]

The Bloggs family keep getting invited to birthday parties, and they feel they must buy the person who invites them a present. The trouble is they do not have much money!

The family has come up with a strategy. Whenever they go to a shop to buy a present, they will not buy the cheapest present (that would seem mean!), so they buy the second cheapest gift they can find. Your task here is to help them quickly find the second least expensive gift in the shop.

[입력]

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 price in the form of a decimal number with 2 places of decimals (ie dollars and cents).

[출력]

Output the second lowest price on a line by itself. It must be in the same format as with the input.

[Source Code]

#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;


int main() {
	int test;
	cin >> test;
	double *money = new double[test];

	for(int i = 0; i < test; i++){
		double input;
		cin >> input;
		money[i] = input;
	}

	sort(money, money+test);

	printf("%.2f", money[1]);
}

[결과 화면]