1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include <iostream> using namespace std; struct drink { int cost, power; } a, b; double ratio_of_drink (const drink arg0) { return arg0.cost/arg0.power; } drink split(const string arg0) { string temp[2]; int j=0; for (auto it=arg0.begin(); it!=arg0.end(); it++) { if (*it == ' ') { j++; continue; } temp[j].insert(temp[j].end(), *it); } drink result; result.cost = stoi(temp[0], nullptr); result.power = stoi(temp[1], nullptr); return result; } int main(void){ string buffer; getline(cin, buffer); a = split(buffer); getline(cin, buffer); b = split(buffer); double ratio_a = ratio_of_drink(a); double ratio_b = ratio_of_drink(b); if (ratio_a>ratio_b) cout << '1'; else cout << '2'; return 0; } |
Direct link: https://paste.plurk.com/show/2321878