Hatena::Grouptopcoder

TopCoderの問題を解く

解いた問題の一覧表

2009-07-23

ProfitCalculator

| 05:33

問題文

利益率を計算。

class ProfitCalculator {
public:
    int percent(vector <string> items) {
        double totalPrice=0, totalCost=0;
        for (int i = 0; i < items.size(); i++) {
            double price, cost;
            istringstream(items[i]) >> price >> cost;
            totalPrice += price;
            totalCost += cost;
        }
        return static_cast<int>(floor((1-totalCost/totalPrice)*100));
    }
};