oula


私信TA

用户名:wielch

访问量:555

签 名:

等  级
排  名 20417
经  验 654
参赛次数 0
文章发表 5
年  龄 0
在职情况 学生
学  校 湖南工业大学
专  业

  自我简介:

解题思路:
这其实就是if语句的理解
注意事项:
还有更快的写法,利润到了某一档时,它前面的奖金是固定的,不用去计算了
参考代码:

#include <stdio.h>


int CalculateReward(int Profit);


int main(void)

{

    int profit = 0;

    scanf("%d",&profit);

    int reward = CalculateReward(profit);

    printf("%d\n",reward);

    return 0;

}


int CalculateReward(int Profit)

{

    int re = 0;

    if(Profit >  1000000)

    {

        re = (Profit - 1000000) / 100;

        Profit = 1000000;

    }

    if(Profit > 600000 && Profit <= 1000000)

    {

        re += (Profit - 600000) * 15 / 1000;

        Profit = 600000;

    }

    if(Profit > 400000 && Profit <= 600000)

    {

        re += (Profit - 400000) * 3 / 100;

        Profit = 400000;

    }

    if(Profit > 200000 && Profit <= 400000)

    {

        re += (Profit - 200000) * 5 / 100;

        Profit = 200000;

    }

    if(Profit > 100000 && Profit <= 200000)

    {

        re += (Profit - 100000) * 75 / 1000;

        Profit = 100000;

    }

    if(Profit <= 100000)

    {

        re += Profit / 10;

    }


    return re;

}



 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区