선택은 나의 것

[SWEA] 1970 쉬운 거스름돈 본문

☽ Algorithm/SWEA

[SWEA] 1970 쉬운 거스름돈

Algoribi 2021. 8. 13. 13:10

문제

SWEA 1970 : 쉬운 거스름돈

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

접근

거슬러 줘야 하는 금액 N을 큰 화폐부터 순서대로 나눠보면 되는 문제이다.

코드

#include <iostream>
#define endl "\n"

using namespace std;

int main() {
    int test_case;
    cin >> test_case;
    for (int t = 1; t <= test_case; t++) {
        int money[] = {50000, 10000, 5000, 1000, 500, 100, 50, 10}, ans[8] = {0};
        int n;
        cin >> n;
        for (int i = 0; i < 8; i++) {
            int a = n / money[i];
            n = n % money[i];
            ans[i] = a;
        }
        cout << "#" << t << endl;
        for (int i = 0; i < 8; i++)
            cout << ans[i] << " ";
        cout << endl;
    }
}

 

깃 허브 주소 : https://github.com/algoribi/algorithm-study

Comments