백준 algorithm
백준 5585 - 거스름돈
cosmohoo
2020. 7. 4. 10:47
반응형
=> 단순 구현 문제입니다.
-
pay = 1000 - pay를 실행한다.
-
큰 단위의 수로 거스름돈을 최대한 많이 채운다.
-
1까지 채운 이후의 동전 개수를 구한다.
=> 단순한 문제이기 때문에 이 이상 설명은 하지 않겠습니다.
<code>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int yen[6]={500,100,50,10,5,1};
int pay;
cin >> pay;
pay = 1000-pay;
int cnt=0;
for(int i=0; i<6; i++)
{
int tmp = pay / yen[i];
if(tmp > 0)
{
pay %= yen[i];
cnt += tmp;
}
}
cout <<cnt <<'\n';
return 0;
}
반응형