1093. Air Express
| |||||||||
| |||||||||
Description
Fly It Today! (FIT), an air express company, charges different amounts for packages depending on their weight. For example, one set of rates may be:
Input
The input file will have one or more data sets. Each data set begins with exactly 4 lines, giving the shipping rates. These will be: You may assume all of these values are positive integers less than 1001 and weight1 < weight2 < weight3 . The values represent the rate table below: There will then be 1 or more lines of customer package sizes. Each of these will be a positive integer less than 1001. The end of customer package sizes is indicated by the single integer 0.
Output
For each input set, print the input set number. Then, for each of the customer package sizes in the input set, create a line of output formatted as follows: Weight (<w>) has best price $<price> (add <p> pounds)
Sample Input
9 10 49 5 99 3 2 8 10 90 100 200 0 10 10 20 20 30 30 100 1 12 29 50 0
Sample Output
Set number 1: Weight (8) has best price $50 (add 2 pounds) Weight (10) has best price $50 (add 0 pounds) Weight (90) has best price $200 (add 10 pounds) Weight (100) has best price $200 (add 0 pounds) Weight (200) has best price $400 (add 0 pounds) Set number 2: Weight (1) has best price $10 (add 0 pounds) Weight (12) has best price $240 (add 0 pounds) Weight (29) has best price $870 (add 0 pounds) Weight (50) has best price $5000 (add 0 pounds) |
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
int a[101];
using namespace std;
int main()
{
int a1,r1;
int a2,r2;
int a3,r3;
int r4;
int i=1;
while(cin>>a1>>r1){
cin>>a2>>r2;
cin>>a3>>r3;
cin>>r4;
int count=0;
int n;
while(cin>>n&&n!=0)
{a[count]=n;count++;}
cout<<"Set number "<<i++<<":"<<endl;
for(int i=0;i<count;i++)
{int min=0;
int jia=0;
if(a[i]<=a1) {min=a[i]*r1;
if(r2*(a1+1)<min){
min=r2*(a1+1);jia=a1+1-a[i];}
}
else if(a1<a[i]&&a[i]<=a2){min=a[i]*r2;
if(r3*(a2+1)<min) {
min=r3*(a2+1);jia=a2+1-a[i];}
}
else if(a2<a[i]&&a[i]<=a3){min=a[i]*r3;
if(r4*(a3+1)<min) {
min=r4*(a3+1);jia=a3+1-a[i];}
}
else if(a[i]>a3) {
min=a[i]*r4;jia=0;}
cout<<"Weight ("<<a[i]<<") has best price $"<<min<<" (add "<<jia<<" pounds)"<<endl;
}cout<<endl;
memset(a,0,101);}
return 0;
}