Design ideas
The following rules can be seen according to the calculation:
When buying 6 books, buying 5 and buying 1 is the lowest price.
When buying 7 books, buying 5 sets and 2 sets is the lowest price.
When buying 8 books, buying two sets of 4 is the lowest price.
When buying 9 books, buying 5 sets and 4 sets is the lowest price.
So when the number of books to buy Mol5 3 o'clock is a special case, the rest of the situation has rules to follow.
There are two cases when the remainder of 3.
The first case is to buy only 3, the direct output to buy 3 of this set of prices will be OK.
The second case is to buy 8, 13, 18 ... The number of books to buy minus 8 to buy 5 of the set price after the purchase of two sets of 4 is the lowest price.
SOURCE program code
1#include <iostream>2 using namespacestd;3 4 voidMain ()5 {6 intn,a,b;7 Doublemin;8cout<<"Please enter the number of purchase books:";9Cin>>N;Tena=n%5; One if(a==0) A { -min= (N-A)/5*(8*5)*0.75; - } the if(a==1) - { -min= (N-A)/5*(8*5)*0.75+8; - } + if(a==2) - { +min= (N-A)/5*(8*5)*0.75+15.2; A } at if(a==3) - { - if(n==3) - { -cout<<"lowest Price is: 21.6"<<Endl; -Exit0); in } -Min= (n8)/5*(8*5)*0.75+51.2; to } + if(a==4) - { themin= (N-A)/5*(8*5)*0.75+25.6; * } $cout<<"the lowest price is:"<<min<<Endl;Panax Notoginseng}
Run results
Programming summary
To solve this problem programming is not the primary problem, the use of mathematical methods of how to calculate is the main difficulty, first use of mathematical thinking, as long as the idea is correct, the programming process is very simple. So you need to have enough time to think about the problem before programming!
Buy a book the lowest price question