반응형

문제 출처

https://www.acmicpc.net/problem/5585


소스코드


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
// 단순 반복문 문제
// greedy algorithm
int main(int argc, char** argv) {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int coins[] = {500100501051};
    int nCost, ans=0;
    cin>>nCost;
    int nRemainder = 1000 - nCost;
    for (int i=0; i<6; i++) {
        while (nRemainder - coins[i] >= 0) {
            nRemainder -= coins[i];
            ans++;
            if (nRemainder == 0) {
                break;
            }
        }
    }
    cout<<ans;
    return 0;
}
cs


반응형

'Algorithm' 카테고리의 다른 글

[BOJ 1206] DFS와 BFS  (0) 2019.07.05
[BOJ 1120]문자열  (0) 2019.07.03
[BOJ 4948] 베르트랑 공준  (0) 2019.07.03
[BOJ 10872] 팩토리얼  (0) 2019.07.03
[프로그래머스 12936] 줄 서는 방법  (0) 2019.04.23

+ Recent posts