文章

11

粉丝

0

获赞

13

访问

641

头像
利润提成 题解:
P1040 北京大学机试题
发布于2025年3月11日 21:14
阅读数 26

#include <stdio.h>

int main() {
    int profit;
    float bonus = 0;
    scanf("%d", &profit);
    const int thresholds[] = {100000, 100000, 200000, 200000, 400000, 1000000};
    const float rates[] = {0.10f, 0.075f, 0.05f, 0.03f, 0.015f, 0.01f};
    int remaining = profit;
    for (int i = 0; i < 6; ++i) {
        if (remaining <= 0) break;
        
        int current = (remaining > thresholds[i]) ? thresholds[i] : remaining;
        bonus += current * rates[i];
        remaining -= thresholds[i];
    }
    if (remaining > 0) {
        bonus += remaining * 0.01f;
    }

    printf("%g", bonus);
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发