SRM 154 DIV2 Level One

また売値と買値。今度はマージンを求める。


入力が文字列なのでちょっと面倒だけど、新しい言語を覚えるには丁度いいレベル。

#include <vector>
#include <string>
#include <sstream>
using namespace std;

#define foreach(bind, item) \
    for (typeof ((item).begin()) bind = (item).begin(), __ie = (item).end() ;\
         bind != __ie ; \
         bind++)

class ProfitCalculator
{
public:
    static int percent(vector<string> items)
    {
        double total_cost = 0;
        double total_price = 0;

        foreach (i, items) {
            double cost;
            double price;
            istringstream ss(*i);

            ss >> cost >> price;

            total_cost += cost;
            total_price += price;
        }

        return (int) ((total_cost - total_price) * 100 / total_cost);
    }
};

新しい言語を2個覚えてる(笑