-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5585.cpp
More file actions
52 lines (48 loc) · 818 Bytes
/
5585.cpp
File metadata and controls
52 lines (48 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// 5585. 거스름돈
// 2019.05.21
// 그리디 알고리즘, 구현
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int exchange = 1000 - n;
int count = 0;
// 잔돈이 0보다 클때 가치가 큰 돈부터 계산
while (exchange > 0)
{
if (exchange >= 500) // 500엔
{
exchange -= 500;
count++;
}
else if (exchange >= 100) // 100엔
{
exchange -= 100;
count++;
}
else if (exchange >= 50 && exchange<100) // 50엔
{
exchange -= 50;
count++;
}
else if (exchange >= 10 && exchange<50) // 10엔
{
exchange -= 10;
count++;
}
else if (exchange >= 5 && exchange<10) // 5엔
{
exchange -= 5;
count++;
}
else if (exchange >= 1 && exchange<5) // 1엔
{
exchange -= 1;
count++;
}
}
cout << count << endl;
return 0;
}