鱼C论坛

 找回密码
 立即注册
楼主: 不二如是

[每日一练] 算法2 ◉‿◉ 企业梯度利润提成

[复制链接]
发表于 2018-6-14 21:48:13 | 显示全部楼层
企业发放的奖金根据利润提成。
利润 (I) 低于或等于 10 万元时,奖金可提 10% ;
利润高于 10 万元,低于 20 万元时,低于 10 万元的部分按 10% 提成,高于 10 万元的部分,可可提成 7.5% ;
20 万到 40 万之间时,高于 20 万元的部分,可提成 5% ;
40 万到 60 万之间时高于 40 万元的部分,可提成 3% ;
60 万到 100 万之间时,高于 60 万元的部分,可提成 1.5% ,高于 100 万元时,超过 100 万元的部分按 1% 提成
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-6-25 19:16:47 | 显示全部楼层
学习一下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-7-1 16:22:17 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-7-3 10:54:36 | 显示全部楼层
import java.util.Scanner;

public class test2 {
        public static void main(String[] args) {
                System.out.println("please enter a num:");
                Scanner sc = new Scanner(System.in);
                double profit = sc.nextDouble();
                double reward = getReward(profit);
                System.out.println("reward:" + reward);
        }

        static double getReward(double profit) {
                double reward = 0.0;
                if (profit <= 10) {
                        reward = profit * 0.1;
                } else if (profit < 20) {
                        reward = 10 * 0.1 + (profit - 10) * 0.075;
                } else if (profit < 40) {
                        reward = 10 * 0.1 + 10 * 0.075 + (profit - 20) * 0.05;
                } else if (profit < 60) {
                        reward = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + (profit - 40) * 0.03;
                } else if (profit < 100) {
                        reward = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + 20 * 0.03 + (profit - 60) * 0.015;
                } else {
                        reward = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + 20 * 0.03 + 40 * 0.015 + (profit - 100) * 0.01;
                }
                return reward;
        }
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-7-3 22:23:09 | 显示全部楼层
想看看大神的代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-7-11 14:18:54 | 显示全部楼层
buhuiya
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-7-26 08:31:24 From FishC Mobile | 显示全部楼层
666
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-8-5 21:58:04 | 显示全部楼层
JavaScript
来个递归
  1. <script>
  2.     var array1 = [100000, 100000, 200000, 200000, 400000, 0];
  3.     var array2 = [.1, .075, .05, .03, .015, .01];
  4.     function calc(n, index, result)
  5.     {
  6.         //当 利润 <= 10W 直接计算, 不递归
  7.         if (n <= array1[index]){
  8.             result += n * array2[index];
  9.             return result;
  10.         }else{
  11.             //如果超过一百万, 直接计算超出部分并退出
  12.             if (index == 5){
  13.                 return result + (n * array2[index]);
  14.             }
  15.             //
  16.             n -= array1[index];
  17.             if (n <= array1[index]){
  18.                 result += n * array2[index];
  19.                 return result;
  20.             }
  21.             else {
  22.                 result += array1[index] * array2[index];
  23.             }
  24.             return calc(n, ++index, result)
  25.         }
  26.     }
  27.     window.onload = function (){
  28.         var i = prompt("输入利润: ")
  29.         if (! i){
  30.             alert("大哥, 输入数字, 阿拉伯那种~");
  31.             return;
  32.         }
  33.         console.log(calc(i, 0, 0));
  34.     };
  35. </script>
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-5 22:00:44 | 显示全部楼层
还是不二的算法好
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-10 14:05:37 From FishC Mobile | 显示全部楼层
学习学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-12 11:31:48 | 显示全部楼层
本帖最后由 木Muk 于 2018-8-12 12:49 编辑

来个麻烦的
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <meta charset="utf-8">
  5.     <title>企业梯度利润提成</title>
  6.     <script src="https://cdn.bootcss.com/angular.js/1.4.6/angular.min.js"></script>
  7.   </head>
  8.   <body ng-app="app">
  9.     <br />
  10.     <center ng-controller="cal">
  11.       <label>请输入当月利润: <input type="text" ng-model="profit" />万元</label>
  12.       <p>发放奖金总数为: {{ bonus() }}万元</p>
  13.     </center>
  14.   </body>
  15.   <script type="text/javascript">
  16.     var app = angular.module('app', []);
  17.     app.controller('cal', function($scope) {
  18.       $scope.bonus = function() {
  19.         if (Number($scope.profit) <= 10) {
  20.           return String(Number($scope.profit)*0.1);
  21.         } else if (Number($scope.profit) > 10 && Number($scope.profit) <= 20) {
  22.           return String((Number($scope.profit) - 10) * 0.075 + 10 * 0.1);
  23.         } else if (Number($scope.profit) > 20 && Number($scope.profit) <= 40) {
  24.           return String((Number($scope.profit) - 20) * 0.05 + 10 * 0.075 + 10 * 0.1);
  25.         } else if (Number($scope.profit) > 40 && Number($scope.profit) <= 60) {
  26.           return String((Number($scope.profit) - 40) * 0.03 + 20 * 0.05 + 10 * 0.075 + 10 * 0.1);
  27.         } else if (Number($scope.profit) > 60 && Number($scope.profit) <= 100) {
  28.           return String((Number($scope.profit) - 60) * 0.015 + 20 * 0.03 + 20 * 0.05 + 10 * 0.075 + 10 * 0.1);
  29.         } else {
  30.           return String((Number($scope.profit) - 100) * 0.01 + 40 * 0.015 + 20 * 0.03 + 20 * 0.05 + 10 * 0.075 + 10 * 0.1);
  31.         }
  32.       }
  33.     });
  34.   </script>
  35. </html>
复制代码


确实有点重复,不过复制粘贴挺方便的
改一下吧

  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <meta charset="utf-8">
  5.     <title>企业梯度利润提成</title>
  6.     <script src="https://cdn.bootcss.com/angular.js/1.4.6/angular.min.js"></script>
  7.   </head>
  8.   <body ng-app="app">
  9.     <br />
  10.     <center ng-controller="cal">
  11.       <label>请输入当月利润: <input type="text" ng-model="profit" />万元</label>
  12.       <p>发放奖金总数为: {{ bonus() }}万元</p>
  13.     </center>
  14.   </body>
  15.   <script type="text/javascript">
  16.     var app = angular.module('app', []);
  17.     app.controller('cal', function($scope) {
  18.       $scope.bonus = function() {
  19.         var profit = Number($scope.profit);
  20.         if (profit <= 10) {
  21.           return String(profit*0.1);
  22.         } else if (profit > 10 && profit <= 20) {
  23.           return String((profit - 10) * 0.075 + 10 * 0.1);
  24.         } else if (profit > 20 && profit <= 40) {
  25.           return String((profit - 20) * 0.05 + 10 * 0.075 + 10 * 0.1);
  26.         } else if (profit > 40 && profit <= 60) {
  27.           return String((profit - 40) * 0.03 + 20 * 0.05 + 10 * 0.075 + 10 * 0.1);
  28.         } else if (profit > 60 && profit <= 100) {
  29.           return String((profit - 60) * 0.015 + 20 * 0.03 + 20 * 0.05 + 10 * 0.075 + 10 * 0.1);
  30.         } else {
  31.           return String((profit - 100) * 0.01 + 40 * 0.015 + 20 * 0.03 + 20 * 0.05 + 10 * 0.075 + 10 * 0.1);
  32.         }
  33.       }
  34.     });
  35.   </script>
  36. </html>
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-12 12:51:45 | 显示全部楼层
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <meta charset="utf-8">
  5.     <title>企业梯度利润提成</title>
  6.     <script src="https://cdn.bootcss.com/angular.js/1.4.6/angular.min.js"></script>
  7.   </head>
  8.   <body ng-app="app">
  9.     <br />
  10.     <center ng-controller="cal">
  11.       <label>请输入当月利润: <input type="text" ng-model="profit" />万元</label>
  12.       <p>发放奖金总数为: {{ bonus() }}万元</p>
  13.     </center>
  14.   </body>
  15.   <script type="text/javascript">
  16.     var app = angular.module('app', []);
  17.     app.controller('cal', function($scope) {
  18.       $scope.bonus = function() {
  19.         var bonus = 0;
  20.         var profit = Number($scope.profit);
  21.         if(profit > 100) {
  22.           bonus += (profit-100) * 0.01;
  23.           profit = 100;
  24.         }
  25.         if(profit > 60) {
  26.           bonus += (profit-60) * 0.015;
  27.           profit = 60;
  28.         }
  29.         if(profit > 40) {
  30.           bonus += (profit-40) * 0.03;
  31.           profit = 40;
  32.         }
  33.         if(profit > 20) {
  34.           bonus += (profit-20) * 0.05;
  35.           profit = 20;
  36.         }
  37.         if(profit > 10) {
  38.           bonus += (profit-10) * 0.075;
  39.           profit = 10;
  40.         }
  41.         if(profit <= 10) {
  42.           bonus += profit * 0.1;
  43.         }
  44.         return String(bonus);
  45.       }
  46.     });
  47.   </script>
  48. </html>
复制代码


说好的输入呢
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2018-8-21 18:02:15 | 显示全部楼层
lllllllllllllllllllllllllllllllllllllllllllllllllllll
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-22 22:22:04 | 显示全部楼层
看看

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-8-28 10:17:40 | 显示全部楼层
键盘输入函数怎么写哟
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-9-7 18:50:48 | 显示全部楼层
65654
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-9-20 16:11:47 | 显示全部楼层
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.         <title>2</title>
  5.         <meta charset="utf-8">
  6. </head>
  7. <body>
  8.         <input type="text" name="利润" id="monly"><input type="button" name="计算奖金" value="计算奖金" onclick="jishu()">
  9.         <p id="op"></p>
  10.         <script type="text/javascript">
  11.                 var monnum=0
  12.                 function jishu(){
  13.                         monnum=0
  14.                         var mon=document.getElementById("monly").value;
  15.                         var op=document.getElementById("op")
  16.                         monly(mon)
  17.                         op.innerHTML="你的奖金是:"+monnum
  18.                 }
  19.                 function monly(m){
  20.                         // i表示剩余的钱// 将计算的奖金放入monnum
  21.                         var i
  22.                         if (m>100*10000){
  23.                                 i=100*10000
  24.                                 m=m-100*10000;
  25.                                 monnum+=m*0.01;}
  26.                         else if (m>60*10000 && m<100*10000) {
  27.                                 i=60*10000
  28.                                 m=m-60*10000;
  29.                                 monnum+=m*0.015;}
  30.                         else if (m>40*10000 && m<60*10000) {
  31.                                 i=40*10000
  32.                                 m=m-40*10000;
  33.                                 monnum+=m*0.03;}
  34.                         else if (m>20*10000 && m<40*10000) {
  35.                                 i=20*10000
  36.                                 m=m-20*10000;
  37.                                 monnum+=m*0.05;}
  38.                         else if (m>10*10000 && m<20*10000) {
  39.                                 i=10*10000
  40.                                 m=m-10*10000;
  41.                                 monnum+=m*0.075;}
  42.                         else {
  43.                                 m=m-10*10000;
  44.                                 monnum+=m*0.10;}
  45.                         if(i>10*10000){
  46.                                 monly(i)
  47.                         }
  48.                        
  49.                 }
  50.         </script>
  51. </body>
  52. </html>
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-9-21 10:26:05 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-9-23 10:18:30 | 显示全部楼层
emm
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-9-23 20:29:01 | 显示全部楼层
支持
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-26 21:05

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表