<每日一题> Day8:CodeForces-996A.Hit the Lottery(贪心)

 原题链接

因为数据太水,我直接一发暴力过了......

#include <cstdio>
using namespace std;

int value[5] = {100, 20, 10, 5, 1};

int main() {
    int n, ans = 0;
    scanf("%d", &n);
    while(n > 0) {
        for(int i = 0; i < 5; i ++) {
            if(n >= value[i]) {
                ans ++;
                n -= value[i];
                break;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}
#include <cstdio>
using namespace std;

int value[5] = {100, 20, 10, 5, 1};

int main() {
    int n, ans = 0;
    scanf("%d", &n);
    for(int i = 0; i < 5; i ++) {
        if(n >0) {
            ans += (n / value[i]);
            n = n % value[i];
        }
    }
    printf("%d\n", ans);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/bianjunting/p/10941200.html