1093. Air Express

来源:互联网 发布:图纸绘制软件 编辑:程序博客网 时间:2024/05/19 17:06

终于来水题了。

#include <iostream>using namespace std;int main() {    int set_number = 0;    int weightstd[4], rate[4], m[4];    while(cin >> weightstd[0]) {    set_number++;    cin >> rate[0] >> weightstd[1]    >> rate[1] >> weightstd[2]>> rate[2] >> rate[3];weightstd[3] = 1000;m[0] = 0;for(int i = 1; i < 4; i++) {m[i] = (weightstd[i-1]+1) * rate[i];}cout << "Set number " << set_number << ":" << endl;    int custom_weight;    while(cin >> custom_weight && custom_weight != 0) {    int shouldpay;    for(int i = 0; i < 4; i++) {    if(custom_weight <= weightstd[i]) {    shouldpay = custom_weight * rate[i];    int min = shouldpay, added = 0;    for(int j = i + 1; j < 4; j++) {    if(m[j] < min) {    min = m[j];    added = weightstd[j-1] + 1 - custom_weight;    }    }    cout << "Weight (" << custom_weight             << ") has best price $" << min << " (add " << added << " pounds)" << endl;    break;    }    }    }    cout << endl;    }    return 0;}


0 0