AOJ 2198 - Moonlight Farm

ぶんしょうをよむのがむずかしかったです.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
struct plant{std::string name; double per;plant(std::string,double);};

plant::plant(std::string _name, double _per)
	:name(_name), per(_per) {}

bool psort(const plant &l, const plant &r){
	if(l.per == r.per){
		if(strcmp(l.name.c_str(), r.name.c_str()) > 0)return 0;
		return 1;
	}

	return l.per > r.per;
}

int main(){
	int n;
	while(std::cin >> n, n){
		std::string l;
		int p, a, b, c, d, e, f, s, m;
		std::vector<plant> v;
		while(n--){
			std::cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			int time = a + b + c + (d + e) * m,
				value = f * s * m - p;
			double per = (double)value / (double)time;
			plant pl = plant(l, per);
			v.push_back(pl);
		}
		
		std::sort(v.begin(), v.end(), psort);
		
		std::vector<plant>::iterator it = v.begin();
		while(it != v.end()){
			std::cout << (*it).name << std::endl;
			it++;
		}

		std::cout << "#" << std::endl;
	}
}