sicily 1093 Air Express

水水,注意等于的情况和输出格式...

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int w[5];
 6 int r[5];
 7 
 8 int main()
 9 {
10     int n;
11     int count=0;
12     while(cin >> w[0])
13     {
14         
15         
16         cin >> r[0];
17         for(int i=1; i<3; i++)
18             cin >> w[i] >> r[i];
19         cin >> r[3];
20     
21         count++;
22         cout << "Set number " << count << ":" << endl;
23         int m;
24         while(cin >> m, m)
25         {
26             int flag=1;
27             int i;
28             if(m > w[2])
29             {
30                 cout << "Weight (" << m << ") has best price $" << m*r[3] << " (add " << 0 << " pounds)" << endl;
31                 continue;
32             }
33             for(i=0; i<3; i++)
34             {
35                 if(m <= w[i] && (w[i]+1)*r[i+1] < m*r[i])
36                 {
37                     cout << "Weight (" << m << ") has best price $" << (w[i]+1)*r[i+1] << " (add " << w[i]+1-m << " pounds)" << endl;
38                     break;
39                 }
40                 else if(m <= w[i] && (w[i]+1)*r[i+1] >= m*r[i])
41                 {
42                     cout << "Weight (" << m << ") has best price $" << m*r[i] << " (add " << 0 << " pounds)" << endl;
43                     break;
44                 }
45             }
46         }
47         cout << endl;
48     }
49     return 0;
50 }

 

posted @ 2015-04-15 13:54  dominjune  阅读(148)  评论(0编辑  收藏  举报