PAT乙级 月饼 (25)

计算一下每种月饼每吨多少钱,然后排下顺序,就ok了,从大到小卖.

可以去http://ideone.com/QM6i3X运行看结果

#include "iostream"
#include "vector"
#include "algorithm"
using namespace std;

 
struct yuebing
{
    double num;
    double price;
    double value;
};

bool comp(const yuebing &a,const yuebing &b)  
{  
    
    return a.value>b.value; 
}  

int main()
{
	int count,xuqiu;
	int i;
	double totalprice;
	yuebing input[1005];
	vector result;
	cin>>count>>xuqiu;

	for(i=0;i>input[i].num;
	}

	for(i=0;i>input[i].price;
	}

	for(i=0;i=result[i].num)
		{
			xuqiu -= result[i].num;
			totalprice += result[i].price;
		}
		else
		{
			totalprice += result[i].value*xuqiu;
			xuqiu = 0;
		}
	}


	cout.setf(ios::fixed);  
    cout.setf(ios::showpoint);  
    cout.precision(2); 

    cout<



你可能感兴趣的:(数据结构算法学习)