Buying a book question

Source: Internet
Author: User

Problem:

A bookstore to the "Harry Potter" promotional activities, a total of 5 volumes. Assuming that each volume of the individual sales price of 8 yuan, if the reader to buy a different two volumes, you can deduct 5% of the cost, three volumes more, the benefits are as follows:

Analysis of all possible situations:

It can be seen that the code is written as follows;

#include <stdio.h>intchange[5] = { -, -,Ten,5,0}; //find the largest value in an array//used to remove big savingsintMax_index (inta[5]){      intmax=0; inti;  for(i=0;i<5; i++){          if(Max <A[i]) Max=A[i]; }      returnMax; }  //Bubble Sort//minimum representation for conversion (1,2,2,2,2), (2,2,2,2,1)voidBubbleint*a,intN) {inti,j,temp;  for(i=0; i<n-1; i++)           for(j=i+1; j<n;j++)              if(a[i]<A[j]) {Temp=A[i]; A[i]=A[j]; A[J]=temp; }  }     //Recursive FunctionsintFuncinta[5]){      inti,j,k; intbuf[5]; intcash[5];  for(i=0;i<5; i++) {Cash[i]=0; //Buf[i] = a[i];     }      //Exit Criteria    if(a[0]==a[1]&&a[1]==a[2]&&a[2]==a[3]&&a[3]==a[4]&&a[4] ==0){          return 0; }      //Sort conversions Minimum representationBubble (A,5); //5 Cycles     for(i=1; i<=5; i++){          if(a[5-I.] >=1){               for(k=0;k<5; k++) {Buf[k]=A[k]; }              //minus One             for(j=0; j<=5-i;j++) Buf[j]= buf[j]-1; //continue to recursioncash[i-1] = (5-i+1)*8*change[i-1]+func (BUF); }      }      //returns the maximum value    returnMax_index (Cash); }     intMain () {intb=0; inta[5] = {0,0,0,0,0}; printf ("This procedure assumes that each book is priced at 8 yuan, please enter the number of books:"); scanf ("%d",&b);  for(intI=0; i<b;i++) {A[i%5]+=1; }    floatresult =0; Result=func (a); printf ("total savings%2.2f yuan! \ n", result/ -); }

Run:

Buying a book question

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.