Coding Test/SW Expert Academy

[SWEA] 1970. 쉬운 거스름돈 c++

owls 2022. 11. 16. 17:08
728x90
  • 문제

S마켓에서 손님에게 거슬러 주어야 할 금액 N이 입력되면 돈의 최소 개수로 거슬러 주기 위하여 각 종류의 돈이 몇 개씩 필요한지 출력하라.

 

N이 32850일 경우,
50,000 원 : 0개
10,000 원 : 3개
5,000 원 : 0개
1,000 원 : 2개
500 원 : 1개
100 원 : 3개
50 원 : 1개
10 원 : 0개

 

 

  • 문제 해결
#include<iostream>
#include <vector>
using namespace std;

int main(int argc, char** argv)
{
	int test_case;
	int T;
	
	cin>>T;
    
    int cash = 50000;
	for(test_case = 1; test_case <= T; ++test_case)
	{
		int n = 0;
        cin >> n;
        cout << "#" << test_case << endl;
      	int cash = 50000, div = 5;
        for(int i = 0; i < 8; i++){
        	cout << n / cash << " ";
       	 	n %= cash;
            cash /= div;
      		div = ( div == 2 )? 5 : 2;
		}
        cout << endl;
	}
	return 0;//정상종료시 반드시 0을 리턴해야합니다.
}
728x90