sicily 1093 Air Express

本文深入探讨了程序中水水元素的等价情况及输出格式的重要细节,通过实例代码解释了如何正确处理水水变量的比较与输出,为程序员提供了实用的编程技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 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 }

 

转载于:https://www.cnblogs.com/dominjune/p/4428341.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值