#include <iostream> #include <cstring> #include <cmath> #include <stdio.h> using namespace std; struct { int weight; int rate; }wr[4]; int main() { //freopen("C:/Users/Alfred/Desktop/1.txt", "r", stdin); int k = 1; while(cin >> wr[0].weight) { cout << "Set number " << k << ":" << endl; k++; cin >> wr[0].rate; cin >> wr[1].weight >> wr[1].rate; cin >> wr[2].weight >> wr[2].rate; cin >> wr[3].rate; int n; while(cin >> n && n != 0) { int i = 0; for(; i < 3; i++) //忘记等号。。WA了3次。。。 if(n <= wr[i].weight) break; int cost = wr[i].rate * n; int p = 0; for(; i < 3; i++) { int costTmp = wr[i + 1].rate * (wr[i].weight + 1); if(costTmp < cost) { cost = costTmp; p = wr[i].weight - n + 1; } } printf("Weight (%d) has best price $%d (add %d pounds)/n", n, cost, p); } cout << endl; } return 0; }