【題解】ZeroJudge e800: p7. 影片推薦

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=e800

#include <iostream>
#include <set>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string S;
    int N;
    double P, L, W, R;
    cin >> N;
    set <pair<double, string> > st;
    for (int i=0; i<N; i++){
        cin >> S >> P >> L >> W >> R;
        st.insert({P * W / L * R, S});
    }
    for (auto it=st.rbegin(); it!=st.rend(); it++) {
        cout << (*it).second << '\n';
    }
    return 0;
}

Python code (credit: Amy Chou)

N = int(input())
lst = []
for _ in range(N):
    line = input().split()
    S = line[0]
    P = int(line[1])
    L = int(line[2])
    W = int(line[3])
    R = int(line[4])
    lst.append((P * W / L * R, S))
    
lst.sort(reverse=True)
for (rating, name) in lst:
    print(name)
分享本文 Share with friends