编辑代码

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
  // const arr = (await readline()).split(" ");
  const sennshu = (await readline()).split(" ").map(Number);
  const unndou = new Array(sennshu.length).fill(0).map((_, idx) => idx);
  // 初始栈放入所有人的编号
  const stack = [unndou];
  // 用栈模拟:不断向stack中插入win lost数组,当stack[stack.length-1]的长度为1时,就已经选出了冠军\
  while (stack[stack.length - 1].length > 1) {
    const ids = stack.pop();
    const win = [];
    const lost = [];
    for (let i = 1; i < ids.length; i += 2) {
      const takaiId = ids[i];
      const hikuiId = ids[i - 1];
      if (sennshu[takaiId] > sennshu[hikuiId]) {
        win.push(takaiId);
        lost.push(hikuiId);
      } else {
        lost.push(takaiId);
        win.push(hikuiId);
      }
    }
    if (ids.length % 2 > 0) win.push(ids[ids.length - 1]);
    stack.push(lost);
    stack.push(win);
  }
  const first = stack[stack.length - 1][0];
  const second = stack[stack.length - 2][0];
  stack[stack.length - 3].sort((a, b) => sennshu[a] - sennshu[b]);
  const third = stack[stack.length - 3][0];
  console.log(first + " " + second + " " + third);
})();