코딩로그
[백준/BOJ/C++] 13771번 Presents 본문
[문제]
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]);
}
[결과 화면]
'YJ > C++' 카테고리의 다른 글
[백준/BOJ/C++] 15238번 Pirates (0) | 2021.11.02 |
---|---|
[백준/BOJ/C++] 4589번 Gnome Sequencing (0) | 2021.11.02 |
[백준/BOJ/C++] 12517번 Centauri Prime (Small1) (0) | 2021.11.02 |
[백준/BOJ/C++] 4593번 Rock, Paper, Scissors (0) | 2021.11.02 |
[백준/BOJ/C++] 7581번 Cuboids (0) | 2021.11.02 |