How to buy books the cheapest

Source: Internet
Author: User

Experimental Topics :

A bookstore for the "Harry Potter" series of books for promotional activities, a total of 5 volumes, with numbers 0, 1, 2, 3, 4, a single volume of 8 yuan, the specific discount is as follows:

Discount on this number

2 5%

3 10%

4 20%

5 25%

Depending on the number of volumes purchased and this number, different discount rules will be applicable. The singular book only corresponds to one discount rule, for example, two volume 1, one volume 2, you can enjoy 5% discount, another volume does not enjoy the discount.

The design algorithm calculates the lowest price for the reader to buy a batch of books.

Experimental ideas:

Calculated by calculating the price of 1~10, because more than 10 of the book can correspond to 6~10, for example, 11 and 6 are equivalent, 17 and 7 are equivalent ... The rule of calculation is to put the number n mod 5 =k, and then the corresponding k+5

The final result is as follows

Buy this number (this) 1 2 3 4 5 6 7 8 9 10

Price (RMB) 8 15.2 21.6 25.6 30 38 45.2 51.2 55.6 60

Experiment Code:

#include"stdafx.h"#include"iostream"using namespacestd;intMain () {intb//define the number of books purchased    intM,n; inti; Doublesum=0; cout<<"Please enter the number of books you need to purchase:"<<Endl; CIN>>b; M=b/5; N=b%5; I=n+5; if(i!=8)    {        Switch(n) { Case 0: Sum=m* +*0.75;  Break;  Case 1: Sum=m* +*0.75+8;  Break;  Case 2: Sum=m* +*0.75+ -*0.95;  Break;  Case 3: Sum=m* +*0.75+ -*0.9;  Break;  Case 4: Sum=m* +*0.75+ +*0.8;  Break; }    }        Elsesum= (M-1)* -+4*8*0.8*2; cout<<"Reader Purchase"<<b<<"The lowest price for this book is:"<<Endl; cout<<sum<<Endl; return 0;}

Experiment Experience:

This experiment is not difficult, difficult to do in a limited time to do it, listen to the teacher said this is Microsoft's job title, asked candidates in one hours to compile code, the topic I and small partners in class when the idea has almost come out, the previous psychological or not adjusted to come over, The first teacher to give a question when is very resistance, in the teacher's inspiration to find this problem simple to begin to do, this should be changed. Everything else is OK ~

How to buy books the cheapest

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.