Baekjoon 5585
거스름돈


QUESTION ❔



CODE ⌨️

#include <iostream>

using namespace std;

int coin[6] = { 500, 100, 50, 10, 5, 1 };

int cost;
int cnt = 0;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> cost;

	cost = 1000 - cost;

	for (int i = 0; i < 6; i++)
	{
		if (cost >= coin[i])
		{
			cnt += (cost / coin[i]);
			cost %= coin[i];
		}
	}

	cout << cnt << "\n";

	return 0;
}



RESULT 💛



SIMPLE DISCUSSION ✏️

Greedy 알고리즘 관련 문제였다.



SOURCE 💎

Baekjoon_Link 👈 Click here


*****
NOT A TALENT ❎ NOT GIVING UP ✅
CopyRight ⓒ 2022 DCherish All Rights Reserved.