[C++] 백준 14729 칠무해

2022. 4. 24. 14:10알고리즘

이 문제는 정렬(sorting)문제다. STL에서 제공하는 sort함수로 쉽게 해결이 가능했다.
또한 소수점 세 자릿수까지 출력해야 하기 때문에 precision 함수로 소수점 자릿수를 조절했다.

#include <bits/stdc++.h>
using namespace std;

int main() { 
    vector<double> v;
    int n; cin >> n;
    cout << fixed; cout.precision(3);
    for (int i = 0; i < n; i++) {
        double x; cin >> x;
        v.push_back(x);
    }

    sort(v.begin(), v.end());
    for (int i = 0; i < 7; i++)
        cout << v[i] << '\n';
}