• Home
  • About
    • on Weekend photo

      on Weekend

      𝙎𝙩𝙪𝙙𝙮𝙞𝙣𝙜

    • Learn More
    • Instagram
    • Github
  • Archive
    • All Posts
    • All Tags
    • All Categories
  • Categories
    • Problem Solving
    • TIL
    • Study
    • Etc
    • 필사
  • Projects

[백준] 5585

01 Dec 2020

코드
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

int money;
int ans = 0;

int makeChange(int money, int En) {
	int tmp_money = money;
	if (tmp_money - En >= 0) {
		tmp_money -= En;
		ans++;
		return tmp_money;
	}
	return money;
}
int ens[6] = { 500,100,50,10,5,1 };
int main()
{
	cin >> money;
	money = 1000 - money;

	while (money) {
		for (int i = 0; i < 6; i++) {
			int tmp = makeChange(money, ens[i]);
			if (tmp < money) {
				money = tmp; break;
			}
		}
	}

	cout << ans;
	return 0;
}



problem_solvingc++ Share Tweet +1