main.cpp

来自「中山大学ACM SICILY 1093 air express题目代码」· C++ 代码 · 共 68 行

CPP
68
字号
#include<iostream>
using namespace std;
#include<stdio.h>

int main()
{
	int a[1002];
	int w1,w2,w3,r1,r2,r3,r4;
	while(1)
	{
		cin>>w1>>r1>>w2>>r2>>w3>>r3>>r4;
		int i=0;

		do
		{
			scanf("%d",&a[i]);
			if(a[i]<=0) break;
			else i++;
		}while(1);
		if(a[0]<=0) break;

		for(int k=0;k<i;k++)
		{
			if((a[k]>0)&&(a[k]<=w1))
			{
				if(a[k]*r1>(w1+1)*r2)
				{
					int s=w1+1-a[k];
					cout<<"Weight ("<<a[k]<<") has best price $"<<(w1+1)*r2<<" (add "<<s<<" pounds)"<<endl;
				}
				else cout<<"Weight ("<<a[k]<<") has best price $"<<a[k]*r1<<" (add 0 pounds)"<<endl;
			}
		

			else if((a[k]>=(w1+1))&&(a[k]<=w2))
			{
				if(a[k]*r2>(w2+1)*r3)
				{
					int t=w2+1-a[k];
					cout<<"Weight ("<<a[k]<<") has best price $"<<(w2+1)*r3<<" (add "<<t<<" pounds)"<<endl;
				}
				else cout<<"Weight ("<<a[k]<<") has best price $"<<a[k]*r2<<" (add 0 pounds)"<<endl;
			}

			else 	if((a[k]>=(w2+1))&&(a[k]<=w3))
			{
				if(a[k]*r3>(w3+1)*r4)
				{
					int u=w3+1-a[k];
					cout<<"Weight ("<<a[k]<<") has best price $"<<(w3+1)*r4<<" (add "<<u<<" pounds)"<<endl;
				}
				else cout<<"Weight ("<<a[k]<<") has best price $"<<a[k]*r3<<" (add 0 pounds)"<<endl;	
			}

			else if(a[k]>=(w3+1)) cout<<"Weight ("<<a[k]<<") has best price $"<<a[k]*r4<<" (add 0 pounds)"<<endl;	
		}
		cout<<endl;
	}

   
        cin.get();
        cin.get();
		return 0;
	
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?