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++) cin="">>a[i]>>b[i];}int All=0;double AllMoney=0;double Cost1=0;double Cost2=0;for(int i=0;i<n;i++) 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++)></n;i++)></iostream>