手机版 欢迎访问it开发者社区(www.mfbz.cn)网站

当前位置: > 开发

Coding Game - The Descent

时间:2021/4/14 2:31:03|来源:|点击: 次

The Descent

问题原地址: The Descent。

问题大意:

其实就是用 for 循环检查当前循环体内的最大值,然后输出该最大值。

说的很花里胡哨的,意思就这么简单

解题方案:

/**
 * The while loop represents the game.
 * Each iteration represents a turn of the game
 * where you are given inputs (the heights of the mountains)
 * and where you have to print an output (the index of the mountain to fire on)
 * The inputs you are given are automatically updated according to your last actions.
 **/

// game loop
while (true) {
  // 需要在日志台输出 index,以及找到当前循环体内最高的 山脉 去攻击
  let index = 0,
    mountainHeight = 0;
  for (let i = 0; i < 8; i++) {
    const mountainH = parseInt(readline()); // represents the height of one mountain.
    if (mountainH > mountainHeight) {
      mountainHeight = mountainH;
      index = i;
    }
  }

  // Write an action using console.log()
  // To debug: console.error('Debug messages...');

  console.log(index); // The index of the mountain to fire on.
}

Copyright © 2002-2019 某某自媒体运营 版权所有