알고리즘/백준 문제풀이

백준 5585번, 언어 : C/C++

ya_ya 2021. 3. 13. 17:21
반응형

사용한 메인 알고리즘 : 탐욕 알고리즘(greedy algorithm)

 

#include<iostream>
using namespace std;
int main()
{
	int Pay;
	int result=0;
	cin >> Pay;
	
	Pay = 1000 - Pay;

	result += Pay / 500;
	Pay %= 500;
	result += Pay / 100;
	Pay %= 100;
	result += Pay / 50;
	Pay %= 50;
	result += Pay / 10;
	Pay %= 10;
	result += Pay / 5;
	Pay %= 5;
	result += Pay / 1;
	
	cout << result << endl;
	
	return 0;
}

다른 문제의 코드는 아래 깃허브에 있습니다.

github.com/Ewlrma/Algorithm-Solution-

반응형