Sicily 1093. Air Express

本文介绍了一个基于不同重量段的定价策略程序。通过输入不同重量区间的价格参数和一系列具体物品的重量,程序能够计算并输出每个物品的最佳购买价格及是否需要添加额外重量来获取更优惠的价格。

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

#include <iostream>

using namespace std;

int arr[1000000];

int main(){
	int n1,p1,n2,p2,n3,p3,p4,k=1;
	while(cin >> n1){
		cin >> p1 >> n2 >> p2 >> n3 >> p3 >> p4;
		int n=0;
		while(true){
			cin >> arr[n];
			if(arr[n]==0)break;
			else n++;
		}
		cout << "Set number " << k << ":" << endl;
		k++;
		for(int i=0; i < n; ++i){
			int price1=0,price2=0;
			if(arr[i] <= n1 && arr[i]>= 0){
				price1=arr[i]*p1;
				price2=(n1+1)*p2;
				if(price1 <= price2) cout << "Weight (" << arr[i] << ") has best price $" << price1 <<  " (add 0 pounds)" << endl;
				else cout << "Weight (" << arr[i] << ") has best price $" << price2 <<  " (add " << n1+1-arr[i] << " pounds)" << endl;
			}
			else if(arr[i] <= n2 && arr[i]>= n1+1){
				price1=arr[i]*p2;
				price2=(n2+1)*p3;
				if(price1 <= price2) cout << "Weight (" << arr[i] << ") has best price $" << price1 <<  " (add 0 pounds)" << endl;
				else cout << "Weight (" << arr[i] << ") has best price $" << price2 <<  " (add " << n2+1-arr[i] << " pounds)" << endl;
			}
			else if(arr[i] <=n3 && arr[i] >= n2+1){
				price1=arr[i]*p3;
				price2=(n3+1)*p4;
				if(price1 <= price2) cout << "Weight (" << arr[i] << ") has best price $" << price1 <<  " (add 0 pounds)" << endl;
				else cout << "Weight (" << arr[i] << ") has best price $" << price2 <<  " (add " << n3+1-arr[i] << " pounds)" << endl;
			}
			else if(arr[i] >= n3+1) cout << "Weight (" << arr[i] << ") has best price $" << p4*arr[i] <<  " (add 0 pounds)" << endl;
		}
		cout << endl;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值