The design process and ideas are as follows:
A copy: 8 Yuan
Number and discount: 2, 5%; 3, 10%; 4, 20%; 5, 25%
1 No Discount (8*1) *1=8
2 Ben 5% (different situation) (8*2) *95%=15.2
3 10% (8*3) *90%=21.6
4 20% (8*4) *80%=25.6
5 25% (8*5) *75%=30
6 Copies:
<1>, 2, 2, 2 Total Price: 15.2*3=45.6
<2>, 3, 2, 1 21.6+15.2+8=44.8
<3>, 4, 2 40.8
5, 1 38
7 copies
3, 2, 2 52
3, 3, 1 51.2
3, 4 47.2
2, 5 45.2
8 copies
4, 4 51.2
5, 3 51.6
9 copies
4, 5 55.6
10 copies
5, 5 60
11 copies
10+1 68
12 copies
10+2 75.2
13
10+3 81.6
14
10+4 85.6
15
10+5 90
16
10+6 98
.
.
.
.
.
.
#include <iostream>using namespacestd;#defineN 100voidLeastmoney (intN) { DoubleMarry[n]; marry[0]=8, marry[1]=15.2, marry[2]=21.6, marry[3]=25.6, marry[4]= -, marry[5]= -, marry[6]=45.2, marry[7]=51.2, marry[8]=55.6, marry[9]= -; if(n>9) { for(intI=Ten; i<=n;i++) {Marry[i]=marry[i-Ten]+ -; }} cout<< marry[n]<<Endl;}intMain () {intm; for(inti =0; I <Ten; i++) {cout<<"Please enter the number of books you have purchased:"; CIN>>m; intn=m-1; Leastmoney (n); } return 0;}
Operation Result:
Calculate the lowest price