编辑代码

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

// 创建一个数组用于存储用户的输入
let input = [];
// 当接收到一行输入时,将其去除首尾空格后添加到input数组中
rl.on('line', (line) => {
    input.push(line.trim());
}).on('close', () => { // 当输入结束时,执行以下代码
    // 读取项目数量n
    const n = parseInt(input[0]);
    // 读取权重数组,将其转换为数字数组
    const weights = input[1].split(' ').map(Number);

    // 创建一个数组用于存储项目信息
    let projects = [];
    // 读取每个项目的信息
    for (let i = 2; i < 2 + n; i++) {
        // 将项目信息分割为名称和评分数组
        const project = input[i].split(' ');
        const name = project[0];
        const scores = project.slice(1).map(Number);

        // 计算项目的热度
        let hotness = 0;
        for (let j = 0; j < 5; j++) {
            hotness += scores[j] * weights[j];
        }

        // 将项目的名称和热度添加到projects数组中
        projects.push({ name, hotness });
    }

    // 对项目数组进行排序,首先根据热度降序排序,如果热度相同则根据名称升序排序
    projects.sort((a, b) => {
        if (a.hotness !== b.hotness) {
            return b.hotness - a.hotness;
        } else {
            return a.name.localeCompare(b.name);
        }
    });

    // 遍历排序后的项目数组并打印项目名称
    for (let project of projects) {
        console.log(project.name);
    }
});