OpenJudge exercises (C ++) -- question 4040: Book Purchasing

Source: Internet
Author: User

OpenJudge exercises (C ++) -- question 4040: Book Purchasing
Question:

Total time limit:
1000 ms
Memory limit:
65536kB
Description

An online bookstore offers two discount strategies. Policy 1: free shipping is available if the total amount of books purchased exceeds 100 yuan. Policy 2: If the number of books to be bought is greater than 3, the total amount of books to be bought will enjoy a discount (excluding the freight ). You can select either of the two discount policies. The freight is 20 RMB. Tom wants to buy books on this website. Please help him select the best discount strategy.

Input
There are multiple rows. The first row is the type of books bought N (0 <=n <= 100 ), in the next N rows, enter the number of books to be purchased and the price P (P is not necessarily an integer ). End input when N is-1
Output
Analyze how to enjoy the discount policy for each group of data and output the minimum amount of book purchase payment
Sample Input
22 603 50-1
Sample output
270
Solution:
#include<iostream>using namespace std;int main(){int n;while(cin>>n){if(n==-1){break;}double a[n],b[n];for(int i=0;i<n;i&#43;&#43;) cin="">>a[i]>>b[i];}int All=0;double AllMoney=0;double Cost1=0;double Cost2=0;for(int i=0;i<n;i&#43;&#43;) all="" cost1="AllMoney;" cost2="AllMoney;">3){Cost1*=0.95;Cost1+=20;}else{Cost1+=20;}if(AllMoney>100){}else{Cost2+=20;}if(Cost1<cost2) else="" pre="" return=""><p></p> </cost2)></n;i&#43;&#43;)></n;i&#43;&#43;)></iostream>

Related Article

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.