[#95][알고리즘][SW Expert Academy] 4050. 재관이의 대량 할인

[SW Expert Academy] 4050. 재관이의 대량 할인

문제 링크 (https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWIseXoKEUcDFAWN&categoryId=AWIseXoKEUcDFAWN&categoryType=CODE)

C++풀이
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
    int testCase, N;
    vector<int> input;
    cin >> testCase;
 
    for (int i = 1; i <= testCase; i++) {
        cin >> N;
        input.resize(N);
        int answer = 0;
        for (int j = 0; j < N; j++) {
            cin >> input[j];
        }
        
        //내림차순 정렬
        sort(input.rbegin(), input.rend());
 
        for (int j = 0; j < N; j++) {
            if (j % 3 == 2) {
                //무료인 상품
                continue;
            }
            else {
                //지불할 값
                answer += input[j];
            }
        }
        cout << "#" << i << " " << answer << endl;
    }
}
cs

댓글

가장 많이 본 글