本题在于求单价,即为每一天(每200升牛奶)要多少钱,注意超过1000的当做5天,不足200的忽略

#include<iostream>

#include<string>

using namespace std;

class milk {

public:

double p;  double average;  int vol;  int day;  string s;

};

int main() {

int T,N,i,redex; cin >> T;

milk m[100];  string s;

while (T--)

{

cin >> N;

for (i = 0; i < N; i++)

{

cin >> m[i].s>>m[i].p>>m[i].vol;

if (m[i].vol >= 1000)

m[i].day = 5;    //大于1000的都是5天

else

m[i].day = m[i].vol / 200;

if (m[i].day != 0)

{

m[i].average = m[i].p / m[i].day;

redex = i;

}

}

for (i = 0; i < N; i++)

{

if (m[i].vol < 200)

continue;      //容量小于200的忽略忽略

if (m[i].average < m[redex].average)

redex = i;

if (m[i].average == m[redex].average)

{

if (m[i].vol>m[redex].vol)    //如果价格相等就比较容量

redex = i;

}

}

cout << m[redex].s << endl;

}

return 0;

}

05-28 20:40