Openjudge solution (c + +)--title 4040: Buying book questions

Source: Internet
Author: User

Problem:

Total time limit:
1000ms
Memory Limit:
65536kB
Describe

An online bookstore to hold preferential promotion, there are two kinds of preferential strategies. Strategy one is the total purchase of more than 100 yuan can enjoy free shipping. Strategy Two is that if the number of books is more than 3, then the total purchase of books to enjoy 95 percent discount (excluding freight). Two preferential strategies can not be enjoyed at the same time, up to one of the preferential strategies. The shipping cost is 20 yuan. Xiao Ming wants to buy books on this website, please help him choose the best preferential strategy.

Input
There are many lines, the first line is to buy the kind of book n (0 <= N <= 100), the next n rows each line enters a bibliography of the purchase quantity m and the cost P (p is not necessarily an integer). When n is-1 o'clock end input
Output
for each group of data, analyze how to enjoy the preferential strategy, output the minimum amount of purchase book payment
Sample input
22 603 50-1
Sample output
270

Solution:

#include<iostream>using namespaceStd;int Main(){intN; while(Cin>>N){if(N==-1){ Break;}DoubleA[N],B[N]; for(intI=0;I<N;I++){Cin>>A[I]>>B[I];}intAll=0;DoubleAllmoney=0;DoubleCost1=0;DoubleCost2=0; for(intI=0;I<N;I++){All+=A[I];Allmoney+=A[I]*B[I];}Cost1=Allmoney;Cost2=Allmoney;if(All>3){Cost1*=0.95;Cost1+= -;}Else{Cost1+= -;}if(Allmoney> -){}Else{Cost2+= -;}if(Cost1<Cost2){cout<<Cost1<<Endl;}Else{cout<<Cost2<<Endl;}}return 0; } 

Openjudge solution (c + +)--title 4040: Buying book questions

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.