Find the sum of ladder service charges

I came across this question in an interview with a php development engineer, which was the last one in the written exam

there is a service platform. Users need to charge a service fee for providing services, but there is a ladder relationship between the service charge and the number of orders. Please calculate the total service charge for a specified number of orders according to the following charging standard. How much service fee does the user need to pay if the user places 8 orders?
shows the given column:

< table > < thead > < tr > < th > number of orders < / th > < th > Service charge < / th > < / tr > < / thead > < tbody > < tr > < td > 1-5 < / td > < td > 31 < / td > < / tr > < tr > < td > 6-10 < / td > < td > 30 < / td > < / tr > < tr > < td > 11-50 < / td > < td > 27 < / td > < / tr > < tr > < td > 51-200 < / td > < td > 24 < / td > < / tr > < tr > < td > 201-1000 < / td > < td > 18 < / td > < / tr > < tr > < td > 1001-5000 < / td > < td > 15 < / td > < / tr > < tr > < td > 5001-10000 < / td > < td > 12 < / td > < / tr > < tr > < td > > = 10000 < / td > < td > 10 < / td > < / tr > < / tbody > < / table >

because the user needs to pay a service charge of RMB 245

because he / she needs to pay RMB 551, 330, 15590, 245
.

ideas for solving problems at that time

I didn"t think of a better way during the interview at that time. My idea of solving the problem was to generate a large array of this ladder relationship according to the corresponding price of solving the problem. If there are 8 orders, it is calculated by calculating the sum of array elements with subscript 0 to subscript 7, and if it is greater than the maximum number of ladders, then judge and calculate separately. If there is a better way to solve the problem, I hope you will actively share

purpose

the reason why I want to contribute to this problem is that I want to find more solutions through your wisdom, so that I can learn new solutions from them. Welcome to write an algorithm using php code

Jun.16,2022

should be the same as personal income tax
just make a quick calculation of the deduction.

    [fc]  [fd]
1-5        31                0              0
6-10       30                5            155 = 5 * 31
11-50      27               10            305 = 5 * 31 + 5 * 30
51-200     24               50           1385 = 5 * 31 + 5 * 30 + 40 * 27

so Service charge fee = ( singular - corresponding quick calculation deduction [fc] ) * corresponding service charge + Quick calculation deduction [fd]


this is the same idea as taxing.


it's a bit wasteful to design such an array.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1befd6b-31c8a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1befd6b-31c8a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?